From d00be9ffa8d72c1fd9562f8718041c3441f847d9 Mon Sep 17 00:00:00 2001 From: Adrian Chadd Date: Mon, 28 Mar 2022 20:44:24 -0700 Subject: [PATCH] [amiwm] remove the global 'front' variable This is a pretty straight forward change to remove the global front variable and instead use a couple of accessor functions. This hopefully will make it easier to keep track and debug when the front screen changes. --- client.c | 4 +-- gram.y | 4 +-- icon.c | 2 +- main.c | 16 ++++++------ menu.c | 2 +- module.c | 4 +-- screen.c | 76 ++++++++++++++++++++++++++++++++++---------------------- screen.h | 5 +++- 8 files changed, 66 insertions(+), 47 deletions(-) diff --git a/client.c b/client.c index c23c8f5..c6378ab 100644 --- a/client.c +++ b/client.c @@ -331,7 +331,7 @@ void flushclients() Scrn *scr2; #endif - if((scr = front)) do { + if((scr = get_front_scr())) do { scr = scr->upfront; XQueryTree(dpy, scr->back, &dw1, &dw2, &wins, &nwins); for(i=0; iparent != c->scr->root) { int x,y; diff --git a/gram.y b/gram.y index 80f46b7..fb7857f 100644 --- a/gram.y +++ b/gram.y @@ -103,8 +103,8 @@ stmt : error | SCREEN string { openscreen($2,DefaultRootWindow(dpy)); } | SCREEN NUMBER string { if(($2==DefaultScreen(dpy)||prefs.manage_all) && $2upfront:NULL), $2, $3); } - | MODULE string { create_module((front? front->upfront:NULL), $2, NULL); } + | MODULE string STRING { create_module((get_front_scr() ? get_front_scr()->upfront:NULL), $2, $3); } + | MODULE string { create_module((get_front_scr() ? get_front_scr()->upfront:NULL), $2, NULL); } | INTERSCREENGAP NUMBER { prefs.borderwidth=$2; } | AUTORAISE truth { prefs.autoraise=$2; } | OPAQUEMOVE truth { prefs.opaquemove=$2; } diff --git a/icon.c b/icon.c index ae0d8f2..2db0d17 100644 --- a/icon.c +++ b/icon.c @@ -398,7 +398,7 @@ Icon *createappicon(struct module *m, Window p, char *name, scr=c->scr; } else if(XFindContext(dpy, p, screen_context, (XPointer*)&scr)) - scr=front; + scr = get_front_scr(); if(p==scr->root) p=scr->back; i->scr=scr; diff --git a/main.c b/main.c index dc84fc7..6c8f90f 100644 --- a/main.c +++ b/main.c @@ -540,11 +540,11 @@ void endicondragging(XEvent *e) int wx, wy; Window ch; - scr=front; + scr=get_front_scr(); for(;;) { if(scr->root == e->xbutton.root && e->xbutton.y_root>=scr->y) break; - if((scr=scr->behind)==front) { + if((scr=scr->behind)==get_front_scr()) { badicondrop(); return; } @@ -823,11 +823,11 @@ static void update_clock(void *dontcare) if(server_grabs) return; call_out(prefs.titleclockinterval, 0, update_clock, dontcare); - scr = front; + scr = get_front_scr(); do { redrawmenubar(scr->menubar); scr=scr->behind; - } while(scr!=front); + } while(scr != get_front_scr()); } void cleanup() @@ -836,7 +836,7 @@ void cleanup() struct coevent *e; flushmodules(); flushclients(); - scr=front; + scr = get_front_scr(); while(scr) closescreen(); free_prefs(); @@ -981,7 +981,7 @@ int main(int argc, char *argv[]) c = NULL; if(XFindContext(dpy, event.xany.window, screen_context, (XPointer*)&scr)) - scr=front; + scr = get_front_scr(); } if(XFindContext(dpy, event.xany.window, icon_context, (XPointer*)&i)) i=NULL; @@ -1011,7 +1011,7 @@ int main(int argc, char *argv[]) if(!event.xcreatewindow.override_redirect) { if(!(scr=getscreenbyroot(event.xcreatewindow.parent))) - scr=front; + scr = get_front_scr(); createclient(event.xcreatewindow.window); } #ifdef ASSIMILATE_WINDOWS @@ -1178,7 +1178,7 @@ int main(int argc, char *argv[]) case MapRequest: if(XFindContext(dpy, event.xmaprequest.window, client_context, (XPointer*)&c)) { if(!(scr=getscreenbyroot(event.xmaprequest.parent))) - scr=front; + scr = get_front_scr(); c=createclient(event.xmaprequest.window); } { diff --git a/menu.c b/menu.c index a7fef86..eba1e1f 100644 --- a/menu.c +++ b/menu.c @@ -805,7 +805,7 @@ void menuaction(struct Item *i, struct Item *si) if(item==0) { openscreen("New Screen", DefaultRootWindow(dpy)); realizescreens(); - scr=front->upfront; + scr = get_front_scr()->upfront; screentoback(); } if(item==1) { diff --git a/module.c b/module.c index 0038893..e11e812 100644 --- a/module.c +++ b/module.c @@ -111,7 +111,7 @@ void delete_keygrab(struct module *m, int id) static void destroy_module(struct module *m) { - Scrn *s=front; + Scrn *s = get_front_scr(); delete_keygrab(m, -1); do { Icon *i, *ni; @@ -121,7 +121,7 @@ static void destroy_module(struct module *m) rmicon(i); } s=s->behind; - } while(s!=front); + } while(s != get_front_scr()); disown_item_chain(m, m->menuitems); if(m->in_fd>=0) { remove_fd_from_set(m->in_fd); close(m->in_fd); } if(m->out_fd>=0) { close(m->out_fd); } diff --git a/screen.c b/screen.c index 42d1bf7..05b6886 100644 --- a/screen.c +++ b/screen.c @@ -23,7 +23,23 @@ extern XContext screen_context, client_context, vroot_context; extern void createmenubar(); extern void reparent(Client *); -Scrn *front = NULL, *scr = NULL; +static Scrn *_front = NULL; +Scrn *scr = NULL; + +/* + * Accessor methods to get and set the 'front' screen. + */ +Scrn * +get_front_scr(void) +{ + return _front; +} + +void +set_front_scr(Scrn *s) +{ + _front = s; +} static Scrn *getvroot(Window root) { @@ -58,29 +74,29 @@ void screentoback(void) { Scrn *f; if((!scr)||(scr->back==scr->root)) return; - if(scr==front) { + if(scr == get_front_scr()) { XLowerWindow(dpy, scr->back); - front=scr->behind; + set_front_scr(scr->behind); } else if(scr==getscreenbyroot(scr->root)) { XLowerWindow(dpy, scr->back); scr->upfront->behind=scr->behind; scr->behind->upfront=scr->upfront; - scr->upfront=front->upfront; - scr->behind=front; - front->upfront->behind=scr; - front->upfront=scr; - } else if(scr->behind==front) { + scr->upfront = get_front_scr()->upfront; + scr->behind = get_front_scr(); + get_front_scr()->upfront->behind=scr; + get_front_scr()->upfront=scr; + } else if(scr->behind == get_front_scr()) { XRaiseWindow(dpy, scr->back); - front=scr; + set_front_scr(scr); } else { XRaiseWindow(dpy, scr->back); scr->upfront->behind=scr->behind; scr->behind->upfront=scr->upfront; - scr->upfront=front->upfront; - scr->behind=front; - front->upfront->behind=scr; - front->upfront=scr; - front=scr; + scr->upfront = get_front_scr()->upfront; + scr->behind = get_front_scr(); + get_front_scr()->upfront->behind=scr; + get_front_scr()->upfront=scr; + set_front_scr(scr); } if((f = getscreenbyroot(scr->root))) { init_dri(&f->dri, dpy, f->root, f->cmap, True); @@ -181,8 +197,8 @@ void closescreen(void) term_dri(&scr->dri, dpy, scr->cmap); if(scr->iconcolorsallocated) XFreeColors(dpy, scr->cmap, scr->iconcolor, scr->iconcolorsallocated, 0); - if(front==scr) - front=scr->behind; + if(get_front_scr()==scr) + set_front_scr(scr->behind); dummy=scr->behind; free(scr); scr=dummy; @@ -292,14 +308,14 @@ Scrn *openscreen(char *deftitle, Window root) s->default_tool_pm_w=0; s->default_tool_pm_h=0; - if(front) { - s->behind=front; - s->upfront=front->upfront; - front->upfront->behind=s; - front->upfront=s; + if(get_front_scr()) { + s->behind = get_front_scr(); + s->upfront = get_front_scr()->upfront; + get_front_scr()->upfront->behind=s; + get_front_scr()->upfront=s; } else { s->behind = s->upfront = s; - front = s; + set_front_scr(s); } scr=s; @@ -309,7 +325,7 @@ Scrn *openscreen(char *deftitle, Window root) void realizescreens(void) { - scr = front; + scr = get_front_scr(); do { if(!scr->realized) { @@ -347,7 +363,7 @@ void realizescreens(void) XMapWindow(dpy, scr->back); } scr=scr->behind; - } while(scr!=front); + } while(scr != get_front_scr()); do { if(!scr->realized) { scanwins(); @@ -358,29 +374,29 @@ void realizescreens(void) scr->realized=1; } scr=scr->behind; - } while(scr!=front); + } while(scr != get_front_scr()); } Scrn *getscreen(Window w) { - Scrn *s=front; + Scrn *s = get_front_scr(); if(w && s) do { if(s->back == w || s->root == w) return s; s=s->behind; - } while(s!=front); - return front; + } while(s != get_front_scr()); + return get_front_scr(); } Scrn *getscreenbyroot(Window w) { - Scrn *s=front; + Scrn *s = get_front_scr(); if(s) do { if(s->root == w) return s; s=s->behind; - } while(s!=front); + } while(s != get_front_scr()); return NULL; } diff --git a/screen.h b/screen.h index db76611..f92712c 100644 --- a/screen.h +++ b/screen.h @@ -37,7 +37,10 @@ typedef struct _Scrn { unsigned long iconcolor[256]; } Scrn; -extern Scrn *scr, *front; +extern Scrn *scr; + +Scrn * get_front_scr(void); +void set_front_scr(Scrn *s); extern void closescreen(); extern Scrn * openscreen(char *, Window);