Introduction
Introduction Statistics Contact Development Disclaimer Help
Use default X cursors. - sam - An updated version of the sam text editor.
git clone git://vernunftzentrum.de/sam.git
Log
Files
Refs
LICENSE
---
commit d77dc3305c595d23651ca6cfdbfdf9a7503eac5c
parent 54d4d14c30059f3c06dd717df43c81df193c5e19
Author: Rob King <[email protected]>
Date: Tue, 6 Sep 2016 13:54:33 -0500
Use default X cursors.
Diffstat:
config.h.def | 6 ++++++
include/libg.h | 25 +++++++++++++------------
libXg/cursorswitch.c | 89 +++++++++++++------------------
libXg/getrect.c | 16 ++--------------
libXg/libgint.h | 7 +++----
libXg/xtbinit.c | 11 ++++++-----
samterm/icons.c | 34 -------------------------------
samterm/main.c | 2 +-
samterm/menu.c | 6 +++---
samterm/mesg.c | 6 +++---
samterm/samterm.h | 5 +----
11 files changed, 75 insertions(+), 132 deletions(-)
---
diff --git a/config.h.def b/config.h.def
@@ -44,4 +44,10 @@
"lightblue:thistle")
*/
+/* You can change the default mouse cursor used by sam. By default,
+ * the "left pointer" cursor is used. Some people might prefer the
+ * Xterm-style thin bar. If so, uncomment this line.
+#define DEFAULT_CURSOR XC_xterm
+ */
+
#endif
diff --git a/include/libg.h b/include/libg.h
@@ -6,22 +6,31 @@
* Like Plan9's libg.h, but suitable for inclusion on non-Plan9 machines
*/
-#define Cursor xCursor
#include <X11/Xft/Xft.h>
-#undef Cursor
#include <commands.h>
enum{ EMAXMSG = 128+8192 }; /* max event size */
/*
+ * Cursors
+ */
+
+enum{
+ DefaultCursor,
+ BullseyeCursor,
+ SweepCursor,
+ DeadCursor,
+ LockCursor
+};
+
+/*
* Types
*/
typedef struct Bitmap Bitmap;
typedef struct Point Point;
typedef struct Rectangle Rectangle;
-typedef struct Cursor Cursor;
typedef struct Keystroke Keystroke;
typedef struct Mouse Mouse;
typedef struct Menu Menu;
@@ -66,14 +75,6 @@ struct Keystroke
Point p;
};
-struct Cursor
-{
- Point offset;
- unsigned char clr[2*16];
- unsigned char set[2*16];
- int id; /* init to zero; used by library */
-};
-
struct Menu
{
char **item;
@@ -179,7 +180,7 @@ extern int rectXrect(Rectangle, Rectangle);
extern int eqpt(Point, Point);
extern int eqrect(Rectangle, Rectangle);
extern void border(Bitmap*, Rectangle, int, Fcode, unsigned long);
-extern void cursorswitch(Cursor*);
+extern void cursorswitch(unsigned int);
extern void cursorset(Point);
extern Rectangle bscreenrect(Rectangle*);
extern void bflush(void);
diff --git a/libXg/cursorswitch.c b/libXg/cursorswitch.c
@@ -4,63 +4,48 @@
#include <libg.h>
#include "libgint.h"
-/*
- * Use the id field in Cursor to hold the X id corresponding
- * to the cursor, so that it doesn't have to be recreated on
- * each cursorswitch. This doesn't quite match the semantics
- * of Plan9 libg, since the user could create a cursor (say
- * with malloc) with garbage in the id field; or the user
- * could change the contents of the other fields and we
- * wouldn't know about it. Neither of these happen in
- * existing uses of libg.
- */
-static Cursor arrow =
-{
- {-1, -1},
- {0xFF, 0xE0, 0xFF, 0xE0, 0xFF, 0xC0, 0xFF, 0x00,
- 0xFF, 0x00, 0xFF, 0x80, 0xFF, 0xC0, 0xFF, 0xE0,
- 0xE7, 0xF0, 0xE3, 0xF8, 0xC1, 0xFC, 0x00, 0xFE,
- 0x00, 0x7F, 0x00, 0x3E, 0x00, 0x1C, 0x00, 0x08,
- },
- {0x00, 0x00, 0x7F, 0xC0, 0x7F, 0x00, 0x7C, 0x00,
- 0x7E, 0x00, 0x7F, 0x00, 0x6F, 0x80, 0x67, 0xC0,
- 0x43, 0xE0, 0x41, 0xF0, 0x00, 0xF8, 0x00, 0x7C,
- 0x00, 0x3E, 0x00, 0x1C, 0x00, 0x08, 0x00, 0x00,
- }
-};
+#include "../config.h"
+
+#include <X11/cursorfont.h>
static Bitmap *bsrc, *bmask;
static Rectangle crect = { 0, 0, 16, 16 };
+extern Window _topwindow;
+
+static Cursor sweep;
+static Cursor crosshair;
+static Cursor pirate;
+static Cursor watch;
+static Cursor defcursor;
+
void
-cursorswitch(Cursor *c)
+cursorswitch(unsigned int c)
{
- if(c == 0)
- c = &arrow;
- if(c->id == 0){
- if(bsrc == 0){
- bsrc = balloc(crect, 0);
- bmask = balloc(crect, 0);
- }
- /*
- * Cursor should have fg where "set" is 1,
- * and bg where "clr" is 1 and "set" is 0,
- * and should leave places alone where "set" and "clr" are bot…
- */
- wrbitmap(bsrc, 0, 16, c->set);
-#ifdef CURSORBUG
- /*
- * Some X servers (e.g., Sun X-on-news for some color
- * monitors) don't do XCreatePixmapCursor properly:
- * only the mask gets displayed, all black
- */
- wrbitmap(bmask, 0, 16, c->set);
-#else
- wrbitmap(bmask, 0, 16, c->clr);
- bitblt(bmask, Pt(0,0), bsrc, crect, S|D);
+ Cursor i = defcursor;
+
+ switch (c){
+ case SweepCursor: i = sweep; break;
+ case BullseyeCursor: i = crosshair; break;
+ case DeadCursor: i = pirate; break;
+ case LockCursor: i = watch; break;
+ default: i = defcursor; break;
+ }
+
+ XDefineCursor(_dpy, _topwindow, i);
+}
+
+#ifndef DEFAULT_CURSOR
+#define DEFAULT_CURSOR XC_left_ptr
#endif
- c->id = (int) XCreatePixmapCursor(_dpy, (Pixmap)bsrc->id, (Pix…
- &_fgcolor, &_bgcolor, -c->offset.x, -c->offset.y);
- }
- XDefineCursor(_dpy, (Window)screen.id, (xCursor)c->id);
+
+void
+initcursors(void)
+{
+ sweep = XCreateFontCursor(_dpy, XC_sizing);
+ crosshair = XCreateFontCursor(_dpy, XC_crosshair);
+ pirate = XCreateFontCursor(_dpy, XC_pirate);
+ watch = XCreateFontCursor(_dpy, XC_watch);
+ defcursor = XCreateFontCursor(_dpy, DEFAULT_CURSOR);
}
+
diff --git a/libXg/getrect.c b/libXg/getrect.c
@@ -4,18 +4,6 @@
#include <libg.h>
#include "libgint.h"
-static Cursor sweep={
- {-7, -7},
- {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x07,
- 0xE0, 0x07, 0xE0, 0x07, 0xE3, 0xF7, 0xE3, 0xF7,
- 0xE3, 0xE7, 0xE3, 0xF7, 0xE3, 0xFF, 0xE3, 0x7F,
- 0xE0, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,},
- {0x00, 0x00, 0x7F, 0xFE, 0x40, 0x02, 0x40, 0x02,
- 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x41, 0xE2,
- 0x41, 0xC2, 0x41, 0xE2, 0x41, 0x72, 0x40, 0x38,
- 0x40, 0x1C, 0x40, 0x0E, 0x7F, 0xE6, 0x00, 0x00,}
-};
-
static void
grabcursor(void)
{
@@ -44,7 +32,7 @@ getrect(int but, Mouse *m){
Rectangle r, rc;
but = 1<<(but-1);
- cursorswitch(&sweep);
+ cursorswitch(SweepCursor);
while(m->buttons)
*m = emouse();
grabcursor();
@@ -64,7 +52,7 @@ getrect(int but, Mouse *m){
}while(m->buttons & but);
Return:
- cursorswitch((Cursor *)0);
+ cursorswitch(DefaultCursor);
if(m->buttons & (7^but)){
rc.min.x = rc.max.x = 0;
rc.min.y = rc.max.y = 0;
diff --git a/libXg/libgint.h b/libXg/libgint.h
@@ -14,7 +14,6 @@
* use defines to rename X11 types Cursor, Font, Event
*/
-#define Cursor xCursor
#define Font xFont
#define Event xEvent
@@ -27,10 +26,12 @@ typedef char* caddr_t;
#include <X11/Xutil.h>
#include <X11/Xft/Xft.h>
-#undef Cursor
#undef Font
#undef Event
+/* Cursor initialization */
+void initcursors(void);
+
/* Return a GCs for solid filling/strings/etc., segments/points, and tiling */
extern GC _getfillgc(Fcode, Bitmap*, unsigned long);
extern GC _getcopygc(Fcode, Bitmap*, Bitmap*, int*);
@@ -64,8 +65,6 @@ extern unsigned long _ld2dmask[];
* Conventions:
* The .id field of a Bitmap is an X Pixmap unless the Bitmap is screen,
* in which case it is a Window.
- * The .id field of a Cursor is set to the X xCursor the first time the
- * cursor is used.
* The .id field of a Font is set to the X xFont.
*
* Coordinate conventions: libg bitmaps can have non (0,0) origins,
diff --git a/libXg/xtbinit.c b/libXg/xtbinit.c
@@ -9,7 +9,6 @@
#define COMPRESSMOUSE
-#define Cursor xCursor
#define Font xFont
#define Event xEvent
@@ -29,7 +28,6 @@
#define XtPointer caddr_t
#endif
-#undef Cursor
#undef Font
#undef Event
@@ -59,6 +57,7 @@ XftColor fontcolor;
extern char *machine;
Display *_dpy;
Widget _toplevel;
+Window _topwindow;
unsigned long _bgpixels[MAX_BACKGROUNDS];
int _nbgs;
unsigned long _fgpixel, _bgpixel, _borderpixel;
@@ -210,9 +209,12 @@ xtbinit(Errfunc f, char *class, int *pargc, char **argv, c…
XtSetValues(widg, args, n);
}
+ initcursors();
+
font = XftFontOpenName(_dpy, DefaultScreen(_dpy), getenv("FONT") ? getenv(…
screen.id = 0;
XtRealizeWidget(_toplevel);
+ _topwindow = XtWindow(_toplevel);
pid_t pid = getpid();
XChangeProperty(_dpy, XtWindow(_toplevel), XInternAtom(_dpy, "_NET_WM_PID"…
@@ -894,14 +896,13 @@ raisewindow(void)
{
XEvent e;
Atom a = XInternAtom(_dpy, "_NET_ACTIVE_WINDOW", True);
- Window w = XtWindow(_toplevel);
- XRaiseWindow(_dpy, w);
+ XRaiseWindow(_dpy, _topwindow);
if (a != None){
memset(&e, 0, sizeof(XEvent));
e.type = ClientMessage;
- e.xclient.window = w;
+ e.xclient.window = _topwindow;
e.xclient.message_type = a;
e.xclient.format = 32;
e.xclient.data.l[0] = 1;
diff --git a/samterm/icons.c b/samterm/icons.c
@@ -3,40 +3,6 @@
#include <libc.h>
#include <libg.h>
-Cursor bullseye={
- {-7, -7},
- {0x1F, 0xF8, 0x3F, 0xFC, 0x7F, 0xFE, 0xFB, 0xDF,
- 0xF3, 0xCF, 0xE3, 0xC7, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xE3, 0xC7, 0xF3, 0xCF,
- 0x7B, 0xDF, 0x7F, 0xFE, 0x3F, 0xFC, 0x1F, 0xF8,},
- {0x00, 0x00, 0x0F, 0xF0, 0x31, 0x8C, 0x21, 0x84,
- 0x41, 0x82, 0x41, 0x82, 0x41, 0x82, 0x7F, 0xFE,
- 0x7F, 0xFE, 0x41, 0x82, 0x41, 0x82, 0x41, 0x82,
- 0x21, 0x84, 0x31, 0x8C, 0x0F, 0xF0, 0x00, 0x00,}
-};
-Cursor deadmouse={
- {-7, -7},
- {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x0C, 0x00, 0x8E, 0x1D, 0xC7,
- 0xFF, 0xE3, 0xFF, 0xF3, 0xFF, 0xFF, 0x7F, 0xFE,
- 0x3F, 0xF8, 0x17, 0xF0, 0x03, 0xE0, 0x00, 0x00,},
- {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, 0x82,
- 0x04, 0x41, 0xFF, 0xE1, 0x5F, 0xF1, 0x3F, 0xFE,
- 0x17, 0xF0, 0x03, 0xE0, 0x00, 0x00, 0x00, 0x00,}
-};
-Cursor lockarrow={
- {-7, -7},
- {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,},
- {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x0F, 0xC0, 0x0F, 0xC0,
- 0x03, 0xC0, 0x07, 0xC0, 0x0E, 0xC0, 0x1C, 0xC0,
- 0x38, 0x00, 0x70, 0x00, 0xE0, 0xDB, 0xC0, 0xDB,}
-};
-
uchar darkgreybits[] = {
0xDD, 0xDD, 0x77, 0x77, 0xDD, 0xDD, 0x77, 0x77,
0xDD, 0xDD, 0x77, 0x77, 0xDD, 0xDD, 0x77, 0x77,
diff --git a/samterm/main.c b/samterm/main.c
@@ -16,8 +16,8 @@ extern void hmoveto(int, long, Flayer *);
Text cmd;
Rune *scratch;
long nscralloc;
-Cursor *cursor;
extern Bitmap screen;
+unsigned int cursor;
Mouse mouse;
Flayer *which = 0;
Flayer *flast = 0;
diff --git a/samterm/menu.c b/samterm/menu.c
@@ -129,7 +129,7 @@ menu3hit(void)
case Zerox:
case Reshape:
if(!lock){
- cursorswitch(&bullseye);
+ cursorswitch(BullseyeCursor);
buttons(Down);
if((mouse.buttons&4) && (l = flwhich(mouse.xy)) && get…
duplicate(l, r, l->f.font, m==Reshape);
@@ -141,7 +141,7 @@ menu3hit(void)
case Close:
if(!lock){
- cursorswitch(&bullseye);
+ cursorswitch(BullseyeCursor);
buttons(Down);
if((mouse.buttons&4) && (l = flwhich(mouse.xy)) && !lo…
t=(Text *)l->user1;
@@ -159,7 +159,7 @@ menu3hit(void)
case Write:
if(!lock){
- cursorswitch(&bullseye);
+ cursorswitch(BullseyeCursor);
buttons(Down);
if((mouse.buttons&4) && (l = flwhich(mouse.xy))){
outTs(Twrite, ((Text *)l->user1)->tag);
diff --git a/samterm/mesg.c b/samterm/mesg.c
@@ -324,7 +324,7 @@ void
setlock(void)
{
lock++;
- cursorswitch(cursor = &lockarrow);
+ cursorswitch(cursor = LockCursor);
}
void
@@ -334,7 +334,7 @@ clrlock(void)
if(lock > 0)
lock--;
if(lock == 0)
- cursorswitch(cursor=(Cursor *)0);
+ cursorswitch(cursor=DefaultCursor);
}
void
@@ -671,7 +671,7 @@ hsetsnarf(int nc)
int i;
int n;
- cursorswitch(&deadmouse);
+ cursorswitch(DeadCursor);
s2 = alloc(nc+1);
for(i=0; i<nc; i++)
s2[i] = getch();
diff --git a/samterm/samterm.h b/samterm/samterm.h
@@ -55,10 +55,7 @@ extern Text *text[];
extern uchar *name[];
extern ushort tag[];
extern int nname;
-extern Cursor bullseye;
-extern Cursor deadmouse;
-extern Cursor lockarrow;
-extern Cursor *cursor;
+extern unsigned int cursor;
extern Flayer *which;
extern Flayer *work;
extern Text cmd;
You are viewing proxied material from vernunftzentrum.de. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.