enumerized cursors

This commit is contained in:
Anselm R. Garbe 2006-03-05 13:22:42 +01:00
parent 49c2f17236
commit c4edc4f3fd
4 changed files with 57 additions and 53 deletions

View File

@ -45,7 +45,7 @@ alloc_client(Window w, XWindowAttributes *wa)
DefaultDepth(dpy, screen), CopyFromParent, DefaultDepth(dpy, screen), CopyFromParent,
DefaultVisual(dpy, screen), DefaultVisual(dpy, screen),
CWOverrideRedirect | CWBackPixmap | CWEventMask, &fwa); CWOverrideRedirect | CWBackPixmap | CWEventMask, &fwa);
c->cursor = normal_cursor; c->cursor = cursor[CurNormal];
XDefineCursor(dpy, c->framewin, c->cursor); XDefineCursor(dpy, c->framewin, c->cursor);
c->gc = XCreateGC(dpy, c->framewin, 0, 0); c->gc = XCreateGC(dpy, c->framewin, 0, 0);
XSync(dpy, False); XSync(dpy, False);

View File

@ -16,7 +16,7 @@ cursor_for_motion(Client *c, int x, int y)
int n, e, w, s, tn, te, tw, ts; int n, e, w, s, tn, te, tw, ts;
if(!def.border) if(!def.border)
return normal_cursor; return cursor[CurNormal];
/* rectangle attributes of client are used */ /* rectangle attributes of client are used */
w = x < def.border; w = x < def.border;
@ -30,23 +30,23 @@ cursor_for_motion(Client *c, int x, int y)
ts = s > f->rect.height - bar_height(); ts = s > f->rect.height - bar_height();
if((w && n) || (w && tn) || (n && tw)) if((w && n) || (w && tn) || (n && tw))
return nw_cursor; return cursor[CurNW];
else if((e && n) || (e && tn) || (n && te)) else if((e && n) || (e && tn) || (n && te))
return ne_cursor; return cursor[CurNE];
else if((w && s) || (w && ts) || (s && tw)) else if((w && s) || (w && ts) || (s && tw))
return sw_cursor; return cursor[CurSW];
else if((e && s) || (e && ts) || (s && te)) else if((e && s) || (e && ts) || (s && te))
return se_cursor; return cursor[CurSE];
else if(w) else if(w)
return w_cursor; return cursor[CurW];
else if(e) else if(e)
return e_cursor; return cursor[CurE];
else if(n) else if(n)
return n_cursor; return cursor[CurN];
else if(s) else if(s)
return s_cursor; return cursor[CurS];
return normal_cursor; return cursor[CurNormal];
} }
Align Align
@ -82,29 +82,29 @@ xy2align(XRectangle *rect, int x, int y)
} }
Align Align
cursor2align(Cursor cursor) cursor2align(Cursor cur)
{ {
if(cursor == w_cursor) if(cur == cursor[CurW])
return WEST; return WEST;
else if(cursor == nw_cursor) else if(cur == cursor[CurNW])
return NWEST; return NWEST;
else if(cursor == n_cursor) else if(cur == cursor[CurN])
return NORTH; return NORTH;
else if(cursor == ne_cursor) else if(cur == cursor[CurNE])
return NEAST; return NEAST;
else if(cursor == e_cursor) else if(cur == cursor[CurE])
return EAST; return EAST;
else if(cursor == se_cursor) else if(cur == cursor[CurSE])
return SEAST; return SEAST;
else if(cursor == s_cursor) else if(cur == cursor[CurS])
return SOUTH; return SOUTH;
else if(cursor == sw_cursor) else if(cur == cursor[CurSW])
return SWEST; return SWEST;
return CENTER; /* should not happen */ return CENTER; /* should not happen */
} }
static int static int
check_vert_match(XRectangle * r, XRectangle * neighbor) check_vert_match(XRectangle *r, XRectangle *neighbor)
{ {
/* check if neighbor matches edge */ /* check if neighbor matches edge */
return (((neighbor->y <= r->y) return (((neighbor->y <= r->y)
@ -317,7 +317,7 @@ mouse_move(Client *c)
XGrabServer(dpy); XGrabServer(dpy);
while(XGrabPointer while(XGrabPointer
(dpy, root, False, ButtonMotionMask | ButtonReleaseMask, (dpy, root, False, ButtonMotionMask | ButtonReleaseMask,
GrabModeAsync, GrabModeAsync, None, move_cursor, GrabModeAsync, GrabModeAsync, None, cursor[CurMove],
CurrentTime) != GrabSuccess) CurrentTime) != GrabSuccess)
usleep(20000); usleep(20000);
@ -559,7 +559,7 @@ mouse_resize(Client *c, Align align)
XGrabServer(dpy); XGrabServer(dpy);
while(XGrabPointer while(XGrabPointer
(dpy, c->framewin, False, ButtonMotionMask | ButtonReleaseMask, (dpy, c->framewin, False, ButtonMotionMask | ButtonReleaseMask,
GrabModeAsync, GrabModeAsync, None, resize_cursor, GrabModeAsync, GrabModeAsync, None, cursor[CurResize],
CurrentTime) != GrabSuccess) CurrentTime) != GrabSuccess)
usleep(20000); usleep(20000);

View File

@ -148,18 +148,17 @@ init_atoms()
static void static void
init_cursors() init_cursors()
{ {
normal_cursor = XCreateFontCursor(dpy, XC_left_ptr); cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
resize_cursor = XCreateFontCursor(dpy, XC_sizing); cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
move_cursor = XCreateFontCursor(dpy, XC_fleur); cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
drag_cursor = XCreateFontCursor(dpy, XC_cross); cursor[CurW] = XCreateFontCursor(dpy, XC_left_side);
w_cursor = XCreateFontCursor(dpy, XC_left_side); cursor[CurE] = XCreateFontCursor(dpy, XC_right_side);
e_cursor = XCreateFontCursor(dpy, XC_right_side); cursor[CurN] = XCreateFontCursor(dpy, XC_top_side);
n_cursor = XCreateFontCursor(dpy, XC_top_side); cursor[CurS] = XCreateFontCursor(dpy, XC_bottom_side);
s_cursor = XCreateFontCursor(dpy, XC_bottom_side); cursor[CurNW] = XCreateFontCursor(dpy, XC_top_left_corner);
nw_cursor = XCreateFontCursor(dpy, XC_top_left_corner); cursor[CurNE] = XCreateFontCursor(dpy, XC_top_right_corner);
ne_cursor = XCreateFontCursor(dpy, XC_top_right_corner); cursor[CurSW] = XCreateFontCursor(dpy, XC_bottom_left_corner);
sw_cursor = XCreateFontCursor(dpy, XC_bottom_left_corner); cursor[CurSE] = XCreateFontCursor(dpy, XC_bottom_right_corner);
se_cursor = XCreateFontCursor(dpy, XC_bottom_right_corner);
} }
static void static void
@ -180,7 +179,7 @@ init_screen()
rect.width = DisplayWidth(dpy, screen); rect.width = DisplayWidth(dpy, screen);
rect.height = DisplayHeight(dpy, screen); rect.height = DisplayHeight(dpy, screen);
XDefineCursor(dpy, root, normal_cursor); XDefineCursor(dpy, root, cursor[CurNormal]);
} }
/* /*

View File

@ -10,7 +10,7 @@
#include "ixp.h" #include "ixp.h"
#include "blitz.h" #include "blitz.h"
/* array indexes of atoms */ /* WM atoms */
enum { enum {
WMState, WMState,
WMProtocols, WMProtocols,
@ -18,6 +18,7 @@ enum {
WMLast WMLast
}; };
/* NET atoms */
enum { enum {
NetNumWS, NetNumWS,
NetSelWS, NetSelWS,
@ -25,12 +26,29 @@ enum {
NetLast NetLast
}; };
/* Column modes */
enum { enum {
Colequal, Colequal,
Colstack, Colstack,
Colmax Colmax
}; };
/* Cursor */
enum {
CurNormal,
CurResize,
CurMove,
CurW,
CurE,
CurN,
CurS,
CurNW,
CurNE,
CurSW,
CurSE,
CurLast
};
/* 8-bit qid.path.type */ /* 8-bit qid.path.type */
enum { enum {
Droot, Droot,
@ -70,7 +88,6 @@ typedef struct Area Area;
typedef struct Frame Frame; typedef struct Frame Frame;
typedef struct Client Client; typedef struct Client Client;
struct Area { struct Area {
unsigned short id; unsigned short id;
Frame **frame; Frame **frame;
@ -176,19 +193,7 @@ Default def;
Atom wm_atom[WMLast]; Atom wm_atom[WMLast];
Atom net_atom[NetLast]; Atom net_atom[NetLast];
Cursor normal_cursor; Cursor cursor[CurLast];
Cursor resize_cursor;
Cursor move_cursor;
Cursor drag_cursor;
Cursor w_cursor;
Cursor e_cursor;
Cursor n_cursor;
Cursor s_cursor;
Cursor nw_cursor;
Cursor ne_cursor;
Cursor sw_cursor;
Cursor se_cursor;
unsigned int valid_mask, num_lock_mask; unsigned int valid_mask, num_lock_mask;
/* area.c */ /* area.c */
@ -267,8 +272,8 @@ void init_lock_modifiers();
void mouse_resize(Client *c, Align align); void mouse_resize(Client *c, Align align);
void mouse_move(Client *c); void mouse_move(Client *c);
Cursor cursor_for_motion(Client *c, int x, int y); Cursor cursor_for_motion(Client *c, int x, int y);
Align cursor2align(Cursor cursor); Align cursor2align(Cursor cur);
Align xy2align(XRectangle * rect, int x, int y); Align xy2align(XRectangle *rect, int x, int y);
void drop_move(Client *c, XRectangle *new, XPoint *pt); void drop_move(Client *c, XRectangle *new, XPoint *pt);
void grab_mouse(Window w, unsigned long mod, unsigned int button); void grab_mouse(Window w, unsigned long mod, unsigned int button);
void ungrab_mouse(Window w, unsigned long mod, unsigned int button); void ungrab_mouse(Window w, unsigned long mod, unsigned int button);