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

View File

@ -148,18 +148,17 @@ init_atoms()
static void
init_cursors()
{
normal_cursor = XCreateFontCursor(dpy, XC_left_ptr);
resize_cursor = XCreateFontCursor(dpy, XC_sizing);
move_cursor = XCreateFontCursor(dpy, XC_fleur);
drag_cursor = XCreateFontCursor(dpy, XC_cross);
w_cursor = XCreateFontCursor(dpy, XC_left_side);
e_cursor = XCreateFontCursor(dpy, XC_right_side);
n_cursor = XCreateFontCursor(dpy, XC_top_side);
s_cursor = XCreateFontCursor(dpy, XC_bottom_side);
nw_cursor = XCreateFontCursor(dpy, XC_top_left_corner);
ne_cursor = XCreateFontCursor(dpy, XC_top_right_corner);
sw_cursor = XCreateFontCursor(dpy, XC_bottom_left_corner);
se_cursor = XCreateFontCursor(dpy, XC_bottom_right_corner);
cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
cursor[CurW] = XCreateFontCursor(dpy, XC_left_side);
cursor[CurE] = XCreateFontCursor(dpy, XC_right_side);
cursor[CurN] = XCreateFontCursor(dpy, XC_top_side);
cursor[CurS] = XCreateFontCursor(dpy, XC_bottom_side);
cursor[CurNW] = XCreateFontCursor(dpy, XC_top_left_corner);
cursor[CurNE] = XCreateFontCursor(dpy, XC_top_right_corner);
cursor[CurSW] = XCreateFontCursor(dpy, XC_bottom_left_corner);
cursor[CurSE] = XCreateFontCursor(dpy, XC_bottom_right_corner);
}
static void
@ -180,7 +179,7 @@ init_screen()
rect.width = DisplayWidth(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 "blitz.h"
/* array indexes of atoms */
/* WM atoms */
enum {
WMState,
WMProtocols,
@ -18,6 +18,7 @@ enum {
WMLast
};
/* NET atoms */
enum {
NetNumWS,
NetSelWS,
@ -25,12 +26,29 @@ enum {
NetLast
};
/* Column modes */
enum {
Colequal,
Colstack,
Colmax
};
/* Cursor */
enum {
CurNormal,
CurResize,
CurMove,
CurW,
CurE,
CurN,
CurS,
CurNW,
CurNE,
CurSW,
CurSE,
CurLast
};
/* 8-bit qid.path.type */
enum {
Droot,
@ -70,7 +88,6 @@ typedef struct Area Area;
typedef struct Frame Frame;
typedef struct Client Client;
struct Area {
unsigned short id;
Frame **frame;
@ -176,19 +193,7 @@ Default def;
Atom wm_atom[WMLast];
Atom net_atom[NetLast];
Cursor normal_cursor;
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;
Cursor cursor[CurLast];
unsigned int valid_mask, num_lock_mask;
/* area.c */
@ -267,8 +272,8 @@ void init_lock_modifiers();
void mouse_resize(Client *c, Align align);
void mouse_move(Client *c);
Cursor cursor_for_motion(Client *c, int x, int y);
Align cursor2align(Cursor cursor);
Align xy2align(XRectangle * rect, int x, int y);
Align cursor2align(Cursor cur);
Align xy2align(XRectangle *rect, int x, int y);
void drop_move(Client *c, XRectangle *new, XPoint *pt);
void grab_mouse(Window w, unsigned long mod, unsigned int button);
void ungrab_mouse(Window w, unsigned long mod, unsigned int button);