[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.
This commit is contained in:
Adrian Chadd
2022-03-28 20:44:24 -07:00
parent 84caa252d1
commit d00be9ffa8
8 changed files with 66 additions and 47 deletions

View File

@@ -331,7 +331,7 @@ void flushclients()
Scrn *scr2; Scrn *scr2;
#endif #endif
if((scr = front)) do { if((scr = get_front_scr())) do {
scr = scr->upfront; scr = scr->upfront;
XQueryTree(dpy, scr->back, &dw1, &dw2, &wins, &nwins); XQueryTree(dpy, scr->back, &dw1, &dw2, &wins, &nwins);
for(i=0; i<nwins; i++) for(i=0; i<nwins; i++)
@@ -367,7 +367,7 @@ void flushclients()
} }
*/ */
XFree((void *) wins); XFree((void *) wins);
} while(scr!=front); } while( scr!= get_front_scr());
while((c=clients)) { while((c=clients)) {
if(c->parent != c->scr->root) { if(c->parent != c->scr->root) {
int x,y; int x,y;

4
gram.y
View File

@@ -103,8 +103,8 @@ stmt : error
| SCREEN string { openscreen($2,DefaultRootWindow(dpy)); } | SCREEN string { openscreen($2,DefaultRootWindow(dpy)); }
| SCREEN NUMBER string { if(($2==DefaultScreen(dpy)||prefs.manage_all) && $2<ScreenCount(dpy)) openscreen($3,RootWindow(dpy,$2)); } | SCREEN NUMBER string { if(($2==DefaultScreen(dpy)||prefs.manage_all) && $2<ScreenCount(dpy)) openscreen($3,RootWindow(dpy,$2)); }
| MODULEPATH string { prefs.module_path = $2; } | MODULEPATH string { prefs.module_path = $2; }
| MODULE string STRING { create_module((front? front->upfront:NULL), $2, $3); } | MODULE string STRING { create_module((get_front_scr() ? get_front_scr()->upfront:NULL), $2, $3); }
| MODULE string { create_module((front? front->upfront:NULL), $2, NULL); } | MODULE string { create_module((get_front_scr() ? get_front_scr()->upfront:NULL), $2, NULL); }
| INTERSCREENGAP NUMBER { prefs.borderwidth=$2; } | INTERSCREENGAP NUMBER { prefs.borderwidth=$2; }
| AUTORAISE truth { prefs.autoraise=$2; } | AUTORAISE truth { prefs.autoraise=$2; }
| OPAQUEMOVE truth { prefs.opaquemove=$2; } | OPAQUEMOVE truth { prefs.opaquemove=$2; }

2
icon.c
View File

@@ -398,7 +398,7 @@ Icon *createappicon(struct module *m, Window p, char *name,
scr=c->scr; scr=c->scr;
} else } else
if(XFindContext(dpy, p, screen_context, (XPointer*)&scr)) if(XFindContext(dpy, p, screen_context, (XPointer*)&scr))
scr=front; scr = get_front_scr();
if(p==scr->root) p=scr->back; if(p==scr->root) p=scr->back;
i->scr=scr; i->scr=scr;

16
main.c
View File

@@ -540,11 +540,11 @@ void endicondragging(XEvent *e)
int wx, wy; int wx, wy;
Window ch; Window ch;
scr=front; scr=get_front_scr();
for(;;) { for(;;) {
if(scr->root == e->xbutton.root && e->xbutton.y_root>=scr->y) if(scr->root == e->xbutton.root && e->xbutton.y_root>=scr->y)
break; break;
if((scr=scr->behind)==front) { if((scr=scr->behind)==get_front_scr()) {
badicondrop(); badicondrop();
return; return;
} }
@@ -823,11 +823,11 @@ static void update_clock(void *dontcare)
if(server_grabs) if(server_grabs)
return; return;
call_out(prefs.titleclockinterval, 0, update_clock, dontcare); call_out(prefs.titleclockinterval, 0, update_clock, dontcare);
scr = front; scr = get_front_scr();
do { do {
redrawmenubar(scr->menubar); redrawmenubar(scr->menubar);
scr=scr->behind; scr=scr->behind;
} while(scr!=front); } while(scr != get_front_scr());
} }
void cleanup() void cleanup()
@@ -836,7 +836,7 @@ void cleanup()
struct coevent *e; struct coevent *e;
flushmodules(); flushmodules();
flushclients(); flushclients();
scr=front; scr = get_front_scr();
while(scr) while(scr)
closescreen(); closescreen();
free_prefs(); free_prefs();
@@ -981,7 +981,7 @@ int main(int argc, char *argv[])
c = NULL; c = NULL;
if(XFindContext(dpy, event.xany.window, screen_context, if(XFindContext(dpy, event.xany.window, screen_context,
(XPointer*)&scr)) (XPointer*)&scr))
scr=front; scr = get_front_scr();
} }
if(XFindContext(dpy, event.xany.window, icon_context, (XPointer*)&i)) if(XFindContext(dpy, event.xany.window, icon_context, (XPointer*)&i))
i=NULL; i=NULL;
@@ -1011,7 +1011,7 @@ int main(int argc, char *argv[])
if(!event.xcreatewindow.override_redirect) { if(!event.xcreatewindow.override_redirect) {
if(!(scr=getscreenbyroot(event.xcreatewindow.parent))) if(!(scr=getscreenbyroot(event.xcreatewindow.parent)))
scr=front; scr = get_front_scr();
createclient(event.xcreatewindow.window); createclient(event.xcreatewindow.window);
} }
#ifdef ASSIMILATE_WINDOWS #ifdef ASSIMILATE_WINDOWS
@@ -1178,7 +1178,7 @@ int main(int argc, char *argv[])
case MapRequest: case MapRequest:
if(XFindContext(dpy, event.xmaprequest.window, client_context, (XPointer*)&c)) { if(XFindContext(dpy, event.xmaprequest.window, client_context, (XPointer*)&c)) {
if(!(scr=getscreenbyroot(event.xmaprequest.parent))) if(!(scr=getscreenbyroot(event.xmaprequest.parent)))
scr=front; scr = get_front_scr();
c=createclient(event.xmaprequest.window); c=createclient(event.xmaprequest.window);
} }
{ {

2
menu.c
View File

@@ -805,7 +805,7 @@ void menuaction(struct Item *i, struct Item *si)
if(item==0) { if(item==0) {
openscreen("New Screen", DefaultRootWindow(dpy)); openscreen("New Screen", DefaultRootWindow(dpy));
realizescreens(); realizescreens();
scr=front->upfront; scr = get_front_scr()->upfront;
screentoback(); screentoback();
} }
if(item==1) { if(item==1) {

View File

@@ -111,7 +111,7 @@ void delete_keygrab(struct module *m, int id)
static void destroy_module(struct module *m) static void destroy_module(struct module *m)
{ {
Scrn *s=front; Scrn *s = get_front_scr();
delete_keygrab(m, -1); delete_keygrab(m, -1);
do { do {
Icon *i, *ni; Icon *i, *ni;
@@ -121,7 +121,7 @@ static void destroy_module(struct module *m)
rmicon(i); rmicon(i);
} }
s=s->behind; s=s->behind;
} while(s!=front); } while(s != get_front_scr());
disown_item_chain(m, m->menuitems); disown_item_chain(m, m->menuitems);
if(m->in_fd>=0) { remove_fd_from_set(m->in_fd); close(m->in_fd); } 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); } if(m->out_fd>=0) { close(m->out_fd); }

View File

@@ -23,7 +23,23 @@ extern XContext screen_context, client_context, vroot_context;
extern void createmenubar(); extern void createmenubar();
extern void reparent(Client *); 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) static Scrn *getvroot(Window root)
{ {
@@ -58,29 +74,29 @@ void screentoback(void)
{ {
Scrn *f; Scrn *f;
if((!scr)||(scr->back==scr->root)) return; if((!scr)||(scr->back==scr->root)) return;
if(scr==front) { if(scr == get_front_scr()) {
XLowerWindow(dpy, scr->back); XLowerWindow(dpy, scr->back);
front=scr->behind; set_front_scr(scr->behind);
} else if(scr==getscreenbyroot(scr->root)) { } else if(scr==getscreenbyroot(scr->root)) {
XLowerWindow(dpy, scr->back); XLowerWindow(dpy, scr->back);
scr->upfront->behind=scr->behind; scr->upfront->behind=scr->behind;
scr->behind->upfront=scr->upfront; scr->behind->upfront=scr->upfront;
scr->upfront=front->upfront; scr->upfront = get_front_scr()->upfront;
scr->behind=front; scr->behind = get_front_scr();
front->upfront->behind=scr; get_front_scr()->upfront->behind=scr;
front->upfront=scr; get_front_scr()->upfront=scr;
} else if(scr->behind==front) { } else if(scr->behind == get_front_scr()) {
XRaiseWindow(dpy, scr->back); XRaiseWindow(dpy, scr->back);
front=scr; set_front_scr(scr);
} else { } else {
XRaiseWindow(dpy, scr->back); XRaiseWindow(dpy, scr->back);
scr->upfront->behind=scr->behind; scr->upfront->behind=scr->behind;
scr->behind->upfront=scr->upfront; scr->behind->upfront=scr->upfront;
scr->upfront=front->upfront; scr->upfront = get_front_scr()->upfront;
scr->behind=front; scr->behind = get_front_scr();
front->upfront->behind=scr; get_front_scr()->upfront->behind=scr;
front->upfront=scr; get_front_scr()->upfront=scr;
front=scr; set_front_scr(scr);
} }
if((f = getscreenbyroot(scr->root))) { if((f = getscreenbyroot(scr->root))) {
init_dri(&f->dri, dpy, f->root, f->cmap, True); init_dri(&f->dri, dpy, f->root, f->cmap, True);
@@ -181,8 +197,8 @@ void closescreen(void)
term_dri(&scr->dri, dpy, scr->cmap); term_dri(&scr->dri, dpy, scr->cmap);
if(scr->iconcolorsallocated) if(scr->iconcolorsallocated)
XFreeColors(dpy, scr->cmap, scr->iconcolor, scr->iconcolorsallocated, 0); XFreeColors(dpy, scr->cmap, scr->iconcolor, scr->iconcolorsallocated, 0);
if(front==scr) if(get_front_scr()==scr)
front=scr->behind; set_front_scr(scr->behind);
dummy=scr->behind; dummy=scr->behind;
free(scr); free(scr);
scr=dummy; scr=dummy;
@@ -292,14 +308,14 @@ Scrn *openscreen(char *deftitle, Window root)
s->default_tool_pm_w=0; s->default_tool_pm_w=0;
s->default_tool_pm_h=0; s->default_tool_pm_h=0;
if(front) { if(get_front_scr()) {
s->behind=front; s->behind = get_front_scr();
s->upfront=front->upfront; s->upfront = get_front_scr()->upfront;
front->upfront->behind=s; get_front_scr()->upfront->behind=s;
front->upfront=s; get_front_scr()->upfront=s;
} else { } else {
s->behind = s->upfront = s; s->behind = s->upfront = s;
front = s; set_front_scr(s);
} }
scr=s; scr=s;
@@ -309,7 +325,7 @@ Scrn *openscreen(char *deftitle, Window root)
void realizescreens(void) void realizescreens(void)
{ {
scr = front; scr = get_front_scr();
do { do {
if(!scr->realized) { if(!scr->realized) {
@@ -347,7 +363,7 @@ void realizescreens(void)
XMapWindow(dpy, scr->back); XMapWindow(dpy, scr->back);
} }
scr=scr->behind; scr=scr->behind;
} while(scr!=front); } while(scr != get_front_scr());
do { do {
if(!scr->realized) { if(!scr->realized) {
scanwins(); scanwins();
@@ -358,29 +374,29 @@ void realizescreens(void)
scr->realized=1; scr->realized=1;
} }
scr=scr->behind; scr=scr->behind;
} while(scr!=front); } while(scr != get_front_scr());
} }
Scrn *getscreen(Window w) Scrn *getscreen(Window w)
{ {
Scrn *s=front; Scrn *s = get_front_scr();
if(w && s) if(w && s)
do { do {
if(s->back == w || s->root == w) if(s->back == w || s->root == w)
return s; return s;
s=s->behind; s=s->behind;
} while(s!=front); } while(s != get_front_scr());
return front; return get_front_scr();
} }
Scrn *getscreenbyroot(Window w) Scrn *getscreenbyroot(Window w)
{ {
Scrn *s=front; Scrn *s = get_front_scr();
if(s) if(s)
do { do {
if(s->root == w) if(s->root == w)
return s; return s;
s=s->behind; s=s->behind;
} while(s!=front); } while(s != get_front_scr());
return NULL; return NULL;
} }

View File

@@ -37,7 +37,10 @@ typedef struct _Scrn {
unsigned long iconcolor[256]; unsigned long iconcolor[256];
} Scrn; } Scrn;
extern Scrn *scr, *front; extern Scrn *scr;
Scrn * get_front_scr(void);
void set_front_scr(Scrn *s);
extern void closescreen(); extern void closescreen();
extern Scrn * openscreen(char *, Window); extern Scrn * openscreen(char *, Window);