From b48b3370e256435051f338660f9abc1af4e485b6 Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sun, 29 Sep 2013 17:36:36 +0200 Subject: [PATCH] wmaker: Moved global var with list of cursors to the preferences variable As the cursor choice for each action is actually a user choice, it is logical to put this into the structure, instead of a poorly defined 'extern' in every file. --- src/WindowMaker.h | 48 +++++++++++++++++++++++++++++------------------- src/appicon.c | 3 +-- src/defaults.c | 7 +++---- src/dock.c | 3 +-- src/event.c | 2 -- src/icon.c | 6 ++---- src/main.c | 3 --- src/menu.c | 4 +--- src/moveres.c | 26 ++++++++++++-------------- src/rootmenu.c | 3 +-- src/screen.c | 5 ++--- src/startup.c | 35 ++++++++++++++++------------------- src/wcore.c | 6 ++---- src/winspector.c | 3 +-- 14 files changed, 71 insertions(+), 83 deletions(-) diff --git a/src/WindowMaker.h b/src/WindowMaker.h index 72111819..6e4c0c94 100644 --- a/src/WindowMaker.h +++ b/src/WindowMaker.h @@ -102,25 +102,31 @@ typedef struct WObjDescriptor { #define PRED_BPIXMAPS 4 /* count of WBUT icons */ #endif /* XKB_BUTTON_HINT */ -/* cursors */ -#define WCUR_DEFAULT 0 -#define WCUR_NORMAL 0 -#define WCUR_MOVE 1 -#define WCUR_RESIZE 2 -#define WCUR_TOPLEFTRESIZE 3 -#define WCUR_TOPRIGHTRESIZE 4 -#define WCUR_BOTTOMLEFTRESIZE 5 -#define WCUR_BOTTOMRIGHTRESIZE 6 -#define WCUR_VERTICALRESIZE 7 -#define WCUR_HORIZONRESIZE 8 -#define WCUR_WAIT 9 -#define WCUR_ARROW 10 -#define WCUR_QUESTION 11 -#define WCUR_TEXT 12 -#define WCUR_SELECT 13 -#define WCUR_ROOT 14 -#define WCUR_EMPTY 15 -#define WCUR_LAST 16 +/* Mouse cursors */ +typedef enum { + WCUR_NORMAL, + WCUR_MOVE, + WCUR_RESIZE, + WCUR_TOPLEFTRESIZE, + WCUR_TOPRIGHTRESIZE, + WCUR_BOTTOMLEFTRESIZE, + WCUR_BOTTOMRIGHTRESIZE, + WCUR_VERTICALRESIZE, + WCUR_HORIZONRESIZE, + WCUR_WAIT, + WCUR_ARROW, + WCUR_QUESTION, + WCUR_TEXT, + WCUR_SELECT, + WCUR_ROOT, + WCUR_EMPTY, + + /* Count of the number of cursors defined */ + WCUR_LAST, + + /* Alias for the Default cursor */ + WCUR_DEFAULT = WCUR_NORMAL +} w_cursor; /* geometry displays */ #define WDIS_NEW 0 /* new style */ @@ -449,6 +455,10 @@ extern struct WPreferences { #endif unsigned int restarting:2; } flags; /* internal flags */ + + /* Map table between w_cursor and actual X id */ + Cursor cursor[WCUR_LAST]; + } wPreferences; /****** Global Variables ******/ diff --git a/src/appicon.c b/src/appicon.c index 8e22c36e..63005594 100644 --- a/src/appicon.c +++ b/src/appicon.c @@ -61,7 +61,6 @@ */ /**** Global variables ****/ -extern Cursor wCursor[WCUR_LAST]; extern WDDomain *WDWindowAttributes; extern XContext wWinContext; @@ -852,7 +851,7 @@ Bool wHandleAppIconMove(WAppIcon *aicon, XEvent *event) || abs(ofs_y - ev.xmotion.y) >= MOVE_THRESHOLD) { XChangeActivePointerGrab(dpy, ButtonMotionMask | ButtonReleaseMask | ButtonPressMask, - wCursor[WCUR_MOVE], CurrentTime); + wPreferences.cursor[WCUR_MOVE], CurrentTime); grabbed = 1; } else { break; diff --git a/src/defaults.c b/src/defaults.c index 02f01a3e..22aa716e 100644 --- a/src/defaults.c +++ b/src/defaults.c @@ -161,7 +161,6 @@ static WDECallbackUpdate updateUsableArea; static WDECallbackUpdate setModifierKeyLabels; -extern Cursor wCursor[WCUR_LAST]; static WDECallbackConvert getCursor; static WDECallbackUpdate setCursor; @@ -3225,11 +3224,11 @@ static int setCursor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *ex Cursor *cursor = tdata; long widx = (long) extra_data; - if (wCursor[widx] != None) { - XFreeCursor(dpy, wCursor[widx]); + if (wPreferences.cursor[widx] != None) { + XFreeCursor(dpy, wPreferences.cursor[widx]); } - wCursor[widx] = *cursor; + wPreferences.cursor[widx] = *cursor; if (widx == WCUR_ROOT && *cursor != None) { XDefineCursor(dpy, scr->root_win, *cursor); diff --git a/src/dock.c b/src/dock.c index fd45c1e4..fae31be2 100644 --- a/src/dock.c +++ b/src/dock.c @@ -66,7 +66,6 @@ #define CLIP_FORWARD 2 /**** Global variables ****/ -extern Cursor wCursor[WCUR_LAST]; extern XContext wWinContext; #define MOD_MASK wPreferences.modifier_mask @@ -3699,7 +3698,7 @@ static void handleDockMove(WDock *dock, WAppIcon *aicon, XEvent *event) || abs(ofs_y - ev.xmotion.y) >= MOVE_THRESHOLD) { XChangeActivePointerGrab(dpy, ButtonMotionMask | ButtonReleaseMask | ButtonPressMask, - wCursor[WCUR_MOVE], CurrentTime); + wPreferences.cursor[WCUR_MOVE], CurrentTime); grabbed = 1; } break; diff --git a/src/event.c b/src/event.c index a0ed8f61..ba5b09de 100644 --- a/src/event.c +++ b/src/event.c @@ -80,8 +80,6 @@ extern XContext wWinContext; extern XContext wVEdgeContext; -extern Cursor wCursor[WCUR_LAST]; - extern WShortKey wKeyBindings[WKBD_LAST]; extern int wScreenCount; diff --git a/src/icon.c b/src/icon.c index a8fbc657..6efc4544 100644 --- a/src/icon.c +++ b/src/icon.c @@ -54,8 +54,6 @@ #define CACHE_ICON_PATH "/Library/WindowMaker/CachedPixmaps" #define ICON_BORDER 3 -extern Cursor wCursor[WCUR_LAST]; - static void miniwindowExpose(WObjDescriptor * desc, XEvent * event); static void miniwindowMouseDown(WObjDescriptor * desc, XEvent * event); static void miniwindowDblClick(WObjDescriptor * desc, XEvent * event); @@ -721,7 +719,7 @@ static void set_dockapp_in_icon(WIcon *icon) (attr.all_event_masks & ButtonPressMask)) wHackedGrabButton(Button1, MOD_MASK, icon->core->window, True, ButtonPressMask, GrabModeSync, GrabModeAsync, - None, wCursor[WCUR_ARROW]); + None, wPreferences.cursor[WCUR_ARROW]); } /* Get the RImage from the XWindow wm_hints */ @@ -862,7 +860,7 @@ static void miniwindowMouseDown(WObjDescriptor * desc, XEvent * event) || abs(dy - ev.xmotion.y) >= MOVE_THRESHOLD) { XChangeActivePointerGrab(dpy, ButtonMotionMask | ButtonReleaseMask | ButtonPressMask, - wCursor[WCUR_MOVE], CurrentTime); + wPreferences.cursor[WCUR_MOVE], CurrentTime); grabbed = 1; } else { break; diff --git a/src/main.c b/src/main.c index b110d7b7..36e595ac 100644 --- a/src/main.c +++ b/src/main.c @@ -125,9 +125,6 @@ Atom _XA_WINDOWMAKER_ICON_TILE; Atom _XA_WM_IGNORE_FOCUS_EVENTS; -/* cursors */ -Cursor wCursor[WCUR_LAST]; - #ifdef SHAPE Bool wShapeSupported; int wShapeEventBase; diff --git a/src/menu.c b/src/menu.c index 0ececa71..a3f177df 100644 --- a/src/menu.c +++ b/src/menu.c @@ -47,8 +47,6 @@ /****** Global Variables ******/ -extern Cursor wCursor[WCUR_LAST]; - extern XContext wWinContext; #define MOD_MASK wPreferences.modifier_mask @@ -2185,7 +2183,7 @@ static void menuTitleMouseDown(WCoreWindow * sender, void *data, XEvent * event) ButtonMotionMask | ButtonReleaseMask | ButtonPressMask, GrabModeAsync, GrabModeAsync, None, - wCursor[WCUR_MOVE], CurrentTime); + wPreferences.cursor[WCUR_MOVE], CurrentTime); } } break; diff --git a/src/moveres.c b/src/moveres.c index 26b8cf96..7e7cf5a6 100644 --- a/src/moveres.c +++ b/src/moveres.c @@ -60,8 +60,6 @@ */ #define HAS_BORDER_WITH_SELECT(w) ((w)->flags.selected || HAS_BORDER(w)) -/****** Global Variables ******/ -extern Cursor wCursor[WCUR_LAST]; /* *---------------------------------------------------------------------- @@ -564,7 +562,7 @@ static void crossWorkspace(WScreen * scr, WWindow * wwin, int opaque_move, int n if (!opaque_move) { XGrabPointer(dpy, scr->root_win, True, PointerMotionMask | ButtonReleaseMask | ButtonPressMask, GrabModeAsync, - GrabModeAsync, None, wCursor[WCUR_MOVE], CurrentTime); + GrabModeAsync, None, wPreferences.cursor[WCUR_MOVE], CurrentTime); } } @@ -1242,7 +1240,7 @@ int wKeyboardMoveResizeWindow(WWindow * wwin) XGrabServer(dpy); XGrabPointer(dpy, scr->root_win, True, PointerMotionMask | ButtonReleaseMask | ButtonPressMask, GrabModeAsync, - GrabModeAsync, None, wCursor[WCUR_DEFAULT], CurrentTime); + GrabModeAsync, None, wPreferences.cursor[WCUR_DEFAULT], CurrentTime); @@ -1696,7 +1694,7 @@ int wMouseMoveWindow(WWindow * wwin, XEvent * ev) XChangeActivePointerGrab(dpy, ButtonMotionMask | ButtonReleaseMask | ButtonPressMask, - wCursor[WCUR_MOVE], CurrentTime); + wPreferences.cursor[WCUR_MOVE], CurrentTime); started = 1; XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync, CurrentTime); @@ -1988,31 +1986,31 @@ void wMouseResizeWindow(WWindow * wwin, XEvent * ev) if (res == (UP | LEFT)) XChangeActivePointerGrab(dpy, ButtonMotionMask | ButtonReleaseMask | ButtonPressMask, - wCursor[WCUR_TOPLEFTRESIZE], CurrentTime); + wPreferences.cursor[WCUR_TOPLEFTRESIZE], CurrentTime); else if (res == (UP | RIGHT)) XChangeActivePointerGrab(dpy, ButtonMotionMask | ButtonReleaseMask | ButtonPressMask, - wCursor[WCUR_TOPRIGHTRESIZE], CurrentTime); + wPreferences.cursor[WCUR_TOPRIGHTRESIZE], CurrentTime); else if (res == (DOWN | LEFT)) XChangeActivePointerGrab(dpy, ButtonMotionMask | ButtonReleaseMask | ButtonPressMask, - wCursor[WCUR_BOTTOMLEFTRESIZE], CurrentTime); + wPreferences.cursor[WCUR_BOTTOMLEFTRESIZE], CurrentTime); else if (res == (DOWN | RIGHT)) XChangeActivePointerGrab(dpy, ButtonMotionMask | ButtonReleaseMask | ButtonPressMask, - wCursor[WCUR_BOTTOMRIGHTRESIZE], CurrentTime); + wPreferences.cursor[WCUR_BOTTOMRIGHTRESIZE], CurrentTime); else if (res == DOWN || res == UP) XChangeActivePointerGrab(dpy, ButtonMotionMask | ButtonReleaseMask | ButtonPressMask, - wCursor[WCUR_VERTICALRESIZE], CurrentTime); + wPreferences.cursor[WCUR_VERTICALRESIZE], CurrentTime); else if (res & (DOWN | UP)) XChangeActivePointerGrab(dpy, ButtonMotionMask | ButtonReleaseMask | ButtonPressMask, - wCursor[WCUR_VERTICALRESIZE], CurrentTime); + wPreferences.cursor[WCUR_VERTICALRESIZE], CurrentTime); else if (res & (LEFT | RIGHT)) XChangeActivePointerGrab(dpy, ButtonMotionMask | ButtonReleaseMask | ButtonPressMask, - wCursor[WCUR_HORIZONRESIZE], CurrentTime); + wPreferences.cursor[WCUR_HORIZONRESIZE], CurrentTime); XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync, CurrentTime); @@ -2153,7 +2151,7 @@ void wSelectWindows(WScreen * scr, XEvent * ev) if (XGrabPointer(dpy, scr->root_win, False, ButtonMotionMask | ButtonReleaseMask | ButtonPressMask, GrabModeAsync, - GrabModeAsync, None, wCursor[WCUR_DEFAULT], CurrentTime) != Success) { + GrabModeAsync, None, wPreferences.cursor[WCUR_DEFAULT], CurrentTime) != Success) { return; } XGrabServer(dpy); @@ -2215,7 +2213,7 @@ void InteractivePlaceWindow(WWindow * wwin, int *x_ret, int *y_ret, unsigned wid int junk; if (XGrabPointer(dpy, root, True, PointerMotionMask | ButtonPressMask, - GrabModeAsync, GrabModeAsync, None, wCursor[WCUR_DEFAULT], CurrentTime) != Success) { + GrabModeAsync, GrabModeAsync, None, wPreferences.cursor[WCUR_DEFAULT], CurrentTime) != Success) { *x_ret = 0; *y_ret = 0; return; diff --git a/src/rootmenu.c b/src/rootmenu.c index 62a03f71..9a4f36b8 100644 --- a/src/rootmenu.c +++ b/src/rootmenu.c @@ -61,7 +61,6 @@ #define MAX_SHORTCUT_LENGTH 32 extern WDDomain *WDRootMenu; -extern Cursor wCursor[WCUR_LAST]; static WMenu *readMenuPipe(WScreen * scr, char **file_name); static WMenu *readPLMenuPipe(WScreen * scr, char **file_name); @@ -155,7 +154,7 @@ static void execCommand(WMenu * menu, WMenuEntry * entry) cmdline = ExpandOptions(menu->frame->screen_ptr, (char *)entry->clientdata); XGrabPointer(dpy, menu->frame->screen_ptr->root_win, True, 0, - GrabModeAsync, GrabModeAsync, None, wCursor[WCUR_WAIT], CurrentTime); + GrabModeAsync, GrabModeAsync, None, wPreferences.cursor[WCUR_WAIT], CurrentTime); XSync(dpy, 0); if (cmdline) { diff --git a/src/screen.c b/src/screen.c index 32e45fa4..721680e2 100644 --- a/src/screen.c +++ b/src/screen.c @@ -70,7 +70,6 @@ |KeyPressMask|KeyReleaseMask) /**** Global variables ****/ -extern Cursor wCursor[WCUR_LAST]; extern Atom _XA_WINDOWMAKER_STATE; extern Atom _XA_WINDOWMAKER_NOTICEBOARD; @@ -464,7 +463,7 @@ static void createInternalWindows(WScreen * scr) attribs.override_redirect = True; attribs.background_pixmap = None; attribs.background_pixel = scr->white_pixel; - attribs.cursor = wCursor[WCUR_DEFAULT]; + attribs.cursor = wPreferences.cursor[WCUR_DEFAULT]; vmask |= CWColormap; attribs.colormap = scr->w_colormap; scr->dock_shadow = @@ -571,7 +570,7 @@ WScreen *wScreenInit(int screen_number) return NULL; } - XDefineCursor(dpy, scr->root_win, wCursor[WCUR_ROOT]); + XDefineCursor(dpy, scr->root_win, wPreferences.cursor[WCUR_ROOT]); /* screen descriptor for raster graphic library */ rattr.flags = RC_RenderMode | RC_ColorsPerChannel | RC_StandardColormap; diff --git a/src/startup.c b/src/startup.c index c39ecafb..f8e8bbc2 100644 --- a/src/startup.c +++ b/src/startup.c @@ -130,9 +130,6 @@ extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW; extern Atom _XA_GNUSTEP_TITLEBAR_STATE; extern Atom _XA_WM_IGNORE_FOCUS_EVENTS; -/* cursors */ -extern Cursor wCursor[WCUR_LAST]; - #ifndef HAVE_INOTIFY /* special flags */ extern char WDelayedActionSet; @@ -546,21 +543,21 @@ void StartUp(Bool defaultScreenOnly) #endif /* cursors */ - wCursor[WCUR_NORMAL] = None; /* inherit from root */ - wCursor[WCUR_ROOT] = XCreateFontCursor(dpy, XC_left_ptr); - wCursor[WCUR_ARROW] = XCreateFontCursor(dpy, XC_top_left_arrow); - wCursor[WCUR_MOVE] = XCreateFontCursor(dpy, XC_fleur); - wCursor[WCUR_RESIZE] = XCreateFontCursor(dpy, XC_sizing); - wCursor[WCUR_TOPLEFTRESIZE] = XCreateFontCursor(dpy, XC_top_left_corner); - wCursor[WCUR_TOPRIGHTRESIZE] = XCreateFontCursor(dpy, XC_top_right_corner); - wCursor[WCUR_BOTTOMLEFTRESIZE] = XCreateFontCursor(dpy, XC_bottom_left_corner); - wCursor[WCUR_BOTTOMRIGHTRESIZE] = XCreateFontCursor(dpy, XC_bottom_right_corner); - wCursor[WCUR_VERTICALRESIZE] = XCreateFontCursor(dpy, XC_sb_v_double_arrow); - wCursor[WCUR_HORIZONRESIZE] = XCreateFontCursor(dpy, XC_sb_h_double_arrow); - wCursor[WCUR_WAIT] = XCreateFontCursor(dpy, XC_watch); - wCursor[WCUR_QUESTION] = XCreateFontCursor(dpy, XC_question_arrow); - wCursor[WCUR_TEXT] = XCreateFontCursor(dpy, XC_xterm); /* odd name??? */ - wCursor[WCUR_SELECT] = XCreateFontCursor(dpy, XC_cross); + wPreferences.cursor[WCUR_NORMAL] = None; /* inherit from root */ + wPreferences.cursor[WCUR_ROOT] = XCreateFontCursor(dpy, XC_left_ptr); + wPreferences.cursor[WCUR_ARROW] = XCreateFontCursor(dpy, XC_top_left_arrow); + wPreferences.cursor[WCUR_MOVE] = XCreateFontCursor(dpy, XC_fleur); + wPreferences.cursor[WCUR_RESIZE] = XCreateFontCursor(dpy, XC_sizing); + wPreferences.cursor[WCUR_TOPLEFTRESIZE] = XCreateFontCursor(dpy, XC_top_left_corner); + wPreferences.cursor[WCUR_TOPRIGHTRESIZE] = XCreateFontCursor(dpy, XC_top_right_corner); + wPreferences.cursor[WCUR_BOTTOMLEFTRESIZE] = XCreateFontCursor(dpy, XC_bottom_left_corner); + wPreferences.cursor[WCUR_BOTTOMRIGHTRESIZE] = XCreateFontCursor(dpy, XC_bottom_right_corner); + wPreferences.cursor[WCUR_VERTICALRESIZE] = XCreateFontCursor(dpy, XC_sb_v_double_arrow); + wPreferences.cursor[WCUR_HORIZONRESIZE] = XCreateFontCursor(dpy, XC_sb_h_double_arrow); + wPreferences.cursor[WCUR_WAIT] = XCreateFontCursor(dpy, XC_watch); + wPreferences.cursor[WCUR_QUESTION] = XCreateFontCursor(dpy, XC_question_arrow); + wPreferences.cursor[WCUR_TEXT] = XCreateFontCursor(dpy, XC_xterm); /* odd name??? */ + wPreferences.cursor[WCUR_SELECT] = XCreateFontCursor(dpy, XC_cross); Pixmap cur = XCreatePixmap(dpy, DefaultRootWindow(dpy), 16, 16, 1); GC gc = XCreateGC(dpy, cur, 0, NULL); @@ -569,7 +566,7 @@ void StartUp(Bool defaultScreenOnly) XSetForeground(dpy, gc, 0); XFillRectangle(dpy, cur, gc, 0, 0, 16, 16); XFreeGC(dpy, gc); - wCursor[WCUR_EMPTY] = XCreatePixmapCursor(dpy, cur, cur, &black, &black, 0, 0); + wPreferences.cursor[WCUR_EMPTY] = XCreatePixmapCursor(dpy, cur, cur, &black, &black, 0, 0); XFreePixmap(dpy, cur); diff --git a/src/wcore.c b/src/wcore.c index 3e77fbfa..37cf59ac 100644 --- a/src/wcore.c +++ b/src/wcore.c @@ -30,8 +30,6 @@ #include "wcore.h" /****** Global Variables ******/ -/* cursors */ -extern Cursor wCursor[WCUR_LAST]; extern XContext wWinContext; /*---------------------------------------------------------------------- @@ -51,7 +49,7 @@ WCoreWindow *wCoreCreateTopLevel(WScreen *screen, int x, int y, int width, int h vmask = CWBorderPixel | CWCursor | CWEventMask | CWOverrideRedirect | CWColormap; attribs.override_redirect = True; - attribs.cursor = wCursor[WCUR_DEFAULT]; + attribs.cursor = wPreferences.cursor[WCUR_DEFAULT]; attribs.background_pixmap = None; attribs.background_pixel = screen->black_pixel; attribs.border_pixel = border_pixel; @@ -102,7 +100,7 @@ WCoreWindow *wCoreCreate(WCoreWindow *parent, int x, int y, int width, int heigh core = wmalloc(sizeof(WCoreWindow)); vmask = CWBorderPixel | CWCursor | CWEventMask | CWColormap; - attribs.cursor = wCursor[WCUR_DEFAULT]; + attribs.cursor = wPreferences.cursor[WCUR_DEFAULT]; attribs.background_pixmap = None; attribs.background_pixel = parent->screen_ptr->black_pixel; attribs.event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | diff --git a/src/winspector.c b/src/winspector.c index fedc013a..0ee08d63 100644 --- a/src/winspector.c +++ b/src/winspector.c @@ -114,7 +114,6 @@ typedef struct InspectorPanel { unsigned int choosingIcon:1; } InspectorPanel; -extern Cursor wCursor[WCUR_LAST]; extern WDDomain *WDWindowAttributes; static InspectorPanel *panelList = NULL; @@ -1017,7 +1016,7 @@ static void selectWindow(WMWidget *bPtr, void *data) if (XGrabPointer(dpy, scr->root_win, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, - wCursor[WCUR_SELECT], CurrentTime) != GrabSuccess) { + wPreferences.cursor[WCUR_SELECT], CurrentTime) != GrabSuccess) { wwarning("could not grab mouse pointer"); return; } -- 2.11.4.GIT