[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;
#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; i<nwins; i++)
@@ -367,7 +367,7 @@ void flushclients()
}
*/
XFree((void *) wins);
} while(scr!=front);
} while( scr!= get_front_scr());
while((c=clients)) {
if(c->parent != c->scr->root) {
int x,y;

4
gram.y
View File

@@ -103,8 +103,8 @@ stmt : error
| SCREEN string { openscreen($2,DefaultRootWindow(dpy)); }
| SCREEN NUMBER string { if(($2==DefaultScreen(dpy)||prefs.manage_all) && $2<ScreenCount(dpy)) openscreen($3,RootWindow(dpy,$2)); }
| MODULEPATH string { prefs.module_path = $2; }
| MODULE string STRING { create_module((front? front->upfront: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; }

2
icon.c
View File

@@ -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;

16
main.c
View File

@@ -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);
}
{

2
menu.c
View File

@@ -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) {

View File

@@ -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); }

View File

@@ -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;
}

View File

@@ -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);