clients list is no more global

This commit is contained in:
Julien Danjou 2007-10-11 21:50:32 +02:00
parent f840f532e3
commit 12ef66b79a
11 changed files with 93 additions and 96 deletions

View File

@ -40,7 +40,6 @@
#include "util.h"
#include "statusbar.h"
Client *clients = NULL;
Client *sel = NULL;
Client *stack = NULL;
@ -91,6 +90,7 @@ cleanup(awesome_config *awesomeconf)
}
XSetInputFocus(awesomeconf->display, PointerRoot, RevertToPointerRoot, CurrentTime);
XSync(awesomeconf->display, False);
p_delete(&awesomeconf->clients);
p_delete(&awesomeconf);
}
@ -269,6 +269,7 @@ main(int argc, char *argv[])
enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */
Atom netatom[NetLast];
event_handler **handler;
Client **clients;
if(argc >= 2)
{
@ -309,11 +310,13 @@ main(int argc, char *argv[])
/* allocate stuff */
awesomeconf = p_new(awesome_config, get_screen_count(dpy));
clients = p_new(Client *, 1);
for(screen = 0; screen < get_screen_count(dpy); screen++)
{
parse_config(dpy, screen, confpath, &awesomeconf[screen]);
setup(&awesomeconf[screen]);
awesomeconf[screen].clients = clients;
drawstatusbar(dpy, &awesomeconf[screen]);
}

View File

@ -34,7 +34,7 @@
#include "layouts/floating.h"
/* extern */
extern Client *clients, *sel, *stack; /* global client list and stack */
extern Client *sel, *stack; /* global client list and stack */
/** Attach client stack to clients stacks
* \param c the client
@ -219,7 +219,7 @@ setclienttrans(Client *c, double opacity)
* \param c2 second client
*/
static void
client_swap(Client *c1, Client *c2)
client_swap(Client **head, Client *c1, Client *c2)
{
Client *tmp;
@ -243,24 +243,24 @@ client_swap(Client *c1, Client *c2)
if(c2->prev)
c2->prev->next = c2;
if(clients == c1)
clients = c2;
if(*head == c1)
*head = c2;
}
/** Attach client to the beginning of the clients stack
* \param c the client
*/
void
attach(Client * c)
attach(Client **head, Client *c)
{
if(clients)
clients->prev = c;
c->next = clients;
clients = c;
if(*head)
(*head)->prev = c;
c->next = *head;
*head = c;
}
void
updatetitle(Client * c)
updatetitle(Client *c)
{
if(!xgettextprop(c->display, c->win, XInternAtom(c->display, "_NET_WM_NAME", False), c->name, sizeof c->name))
xgettextprop(c->display, c->win, XInternAtom(c->display, "WM_NAME", False), c->name, sizeof c->name);
@ -304,14 +304,14 @@ configure(Client * c)
* \param c client to detach
*/
void
detach(Client * c)
detach(Client **head, Client *c)
{
if(c->prev)
c->prev->next = c->next;
if(c->next)
c->next->prev = c->prev;
if(c == clients)
clients = c->next;
if(c == *head)
*head = c->next;
c->next = c->prev = NULL;
}
@ -452,7 +452,7 @@ manage(Display *disp, Window w, XWindowAttributes *wa, awesome_config *awesomeco
updatetitle(c);
move_client_to_screen(c, awesomeconf, False);
if((rettrans = XGetTransientForHint(disp, w, &trans) == Success))
for(t = clients; t && t->win != trans; t = t->next);
for(t = *awesomeconf->clients; t && t->win != trans; t = t->next);
if(t)
for(i = 0; i < awesomeconf->ntags; i++)
c->tags[i] = t->tags[i];
@ -461,7 +461,7 @@ manage(Display *disp, Window w, XWindowAttributes *wa, awesome_config *awesomeco
if(!c->isfloating)
c->isfloating = (rettrans == Success) || c->isfixed;
saveprops(c, awesomeconf->ntags);
attach(c);
attach(awesomeconf->clients, c);
attachstack(c);
XMoveResizeWindow(disp, c->win, c->x, c->y, c->w, c->h); /* some windows require this */
c->isbanned = True;
@ -588,7 +588,7 @@ unmanage(Client * c, long state, awesome_config *awesomeconf)
/* The server grab construct avoids race conditions. */
XGrabServer(c->display);
XConfigureWindow(c->display, c->win, CWBorderWidth, &wc); /* restore border */
detach(c);
detach(awesomeconf->clients, c);
detachstack(c);
if(sel == c)
focus(c->display, NULL, True, awesomeconf);
@ -760,7 +760,7 @@ uicb_swapnext(Display *disp,
for(next = sel->next; next && !isvisible(next, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags); next = next->next);
if(next)
{
client_swap(sel, next);
client_swap(awesomeconf->clients, sel, next);
arrange(disp, awesomeconf);
}
}
@ -778,7 +778,7 @@ uicb_swapprev(Display *disp,
for(prev = sel->prev; prev && !isvisible(prev, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags); prev = prev->prev);
if(prev)
{
client_swap(prev, sel);
client_swap(awesomeconf->clients, prev, sel);
arrange(disp, awesomeconf);
}
}

View File

@ -27,46 +27,12 @@
/** Mask shorthands, used in event.c and client.c */
#define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
typedef struct Client Client;
struct Client
{
/** Client name */
char name[256];
/** Window geometry */
int x, y, w, h;
/** Real window geometry for floating */
int rx, ry, rw, rh;
int basew, baseh, incw, inch, maxw, maxh, minw, minh;
int minax, maxax, minay, maxay;
/** True if client is unmapped */
Bool unmapped;
long flags;
int border, oldborder;
Bool isbanned, isfixed, ismax, isfloating, wasfloating;
/** Tags for the client */
Bool *tags;
/** Next client */
Client *next;
/** Previous client */
Client *prev;
Client *snext;
/** Window of the client */
Window win;
/** Client display */
Display *display;
/** Client logical screen */
int screen;
/** Client physical screen */
int phys_screen;
/** First time viewed on new layout */
Bool ftview;
};
void grabbuttons(Client *, Bool, Bool, KeySym, unsigned int);
inline void attach(Client *); /* attaches c to global client list */
inline void attach(Client **, Client *);
inline void detach(Client **, Client *);
void ban(Client *); /* bans c */
void configure(Client *); /* send synthetic configure event */
void detach(Client *); /* detaches c from global client list */
void focus(Display *, Client *, Bool, awesome_config *); /* focus c if visible && !NULL, or focus top visible */
void manage(Display *, Window, XWindowAttributes *, awesome_config *);
void resize(Client *, int, int, int, int, awesome_config *, Bool); /* resize with given coordinates c */

View File

@ -92,6 +92,41 @@ typedef struct
Layout *layout;
} Tag;
typedef struct Client Client;
struct Client
{
/** Client name */
char name[256];
/** Window geometry */
int x, y, w, h;
/** Real window geometry for floating */
int rx, ry, rw, rh;
int basew, baseh, incw, inch, maxw, maxh, minw, minh;
int minax, maxax, minay, maxay;
/** True if client is unmapped */
Bool unmapped;
long flags;
int border, oldborder;
Bool isbanned, isfixed, ismax, isfloating, wasfloating;
/** Tags for the client */
Bool *tags;
/** Next client */
Client *next;
/** Previous client */
Client *prev;
Client *snext;
/** Window of the client */
Window win;
/** Client display */
Display *display;
/** Client logical screen */
int screen;
/** Client physical screen */
int phys_screen;
/** First time viewed on new layout */
Bool ftview;
};
/** Main configuration structure */
struct awesome_config
{
@ -157,6 +192,8 @@ struct awesome_config
Cursor cursor[CurLast];
/** Font */
XftFont *font;
/** Clients list */
Client **clients;
};
void parse_config(Display *, int, const char *, awesome_config *); /* parse configuration file */

24
event.c
View File

@ -36,17 +36,17 @@
#include "layouts/floating.h"
/* extern */
extern Client *clients, *sel; /* global client list */
extern Client *sel;
#define CLEANMASK(mask, screen) (mask & ~(awesomeconf[screen].numlockmask | LockMask))
#define MOUSEMASK (BUTTONMASK | PointerMotionMask)
static Client *
getclient(Window w)
getclient(Client **list, Window w)
{
Client *c;
for(c = clients; c && c->win != w; c = c->next);
for(c = *list; c && c->win != w; c = c->next);
return c;
}
@ -198,7 +198,7 @@ handle_event_buttonpress(XEvent * e, awesome_config *awesomeconf)
return;
}
if((c = getclient(ev->window)))
if((c = getclient(awesomeconf->clients, ev->window)))
{
focus(c->display, c, ev->same_screen, &awesomeconf[c->screen]);
if(CLEANMASK(ev->state, c->screen) != awesomeconf[c->screen].modkey)
@ -258,7 +258,7 @@ handle_event_configurerequest(XEvent * e, awesome_config *awesomeconf)
XConfigureRequestEvent *ev = &e->xconfigurerequest;
XWindowChanges wc;
if((c = getclient(ev->window)))
if((c = getclient(awesomeconf->clients, ev->window)))
{
c->ismax = False;
if(ev->value_mask & CWBorderWidth)
@ -334,7 +334,7 @@ handle_event_destroynotify(XEvent * e, awesome_config *awesomeconf)
Client *c;
XDestroyWindowEvent *ev = &e->xdestroywindow;
if((c = getclient(ev->window)))
if((c = getclient(awesomeconf->clients, ev->window)))
unmanage(c, WithdrawnState, &awesomeconf[c->screen]);
}
@ -347,7 +347,7 @@ handle_event_enternotify(XEvent * e, awesome_config *awesomeconf)
if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
return;
if((c = getclient(ev->window)))
if((c = getclient(awesomeconf->clients, ev->window)))
{
if(!sel || sel != c)
{
@ -438,7 +438,7 @@ handle_event_maprequest(XEvent * e, awesome_config *awesomeconf)
return;
if(wa.override_redirect)
return;
if(!getclient(ev->window))
if(!getclient(awesomeconf->clients, ev->window))
{
for(screen = 0; wa.screen != ScreenOfDisplay(e->xany.display, screen); screen++);
if(screen == 0)
@ -456,13 +456,13 @@ handle_event_propertynotify(XEvent * e, awesome_config *awesomeconf)
if(ev->state == PropertyDelete)
return; /* ignore */
if((c = getclient(ev->window)))
if((c = getclient(awesomeconf->clients, ev->window)))
{
switch (ev->atom)
{
case XA_WM_TRANSIENT_FOR:
XGetTransientForHint(e->xany.display, c->win, &trans);
if(!c->isfloating && (c->isfloating = (getclient(trans) != NULL)))
if(!c->isfloating && (c->isfloating = (getclient(awesomeconf->clients, trans) != NULL)))
arrange(e->xany.display, &awesomeconf[c->screen]);
break;
case XA_WM_NORMAL_HINTS:
@ -484,7 +484,7 @@ handle_event_unmapnotify(XEvent * e, awesome_config *awesomeconf)
Client *c;
XUnmapEvent *ev = &e->xunmap;
if((c = getclient(ev->window))
if((c = getclient(awesomeconf->clients, ev->window))
&& ev->event == RootWindow(e->xany.display, c->phys_screen) && (ev->send_event || !c->unmapped))
unmanage(c, WithdrawnState, &awesomeconf[c->screen]);
}
@ -494,7 +494,7 @@ handle_event_shape(XEvent * e,
awesome_config *awesomeconf __attribute__ ((unused)))
{
XShapeEvent *ev = (XShapeEvent *) e;
Client *c = getclient(ev->window);
Client *c = getclient(awesomeconf->clients, ev->window);
if(c)
set_shape(c);

View File

@ -30,7 +30,7 @@
#include "layouts/floating.h"
/* extern */
extern Client *clients, *sel; /* global client list */
extern Client *sel;
/** Arrange windows following current selected layout
* \param disp display ref
@ -41,7 +41,7 @@ arrange(Display * disp, awesome_config *awesomeconf)
{
Client *c;
for(c = clients; c; c = c->next)
for(c = *awesomeconf->clients; c; c = c->next)
{
if(isvisible(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags))
unban(c);
@ -65,7 +65,7 @@ uicb_focusnext(Display *disp __attribute__ ((unused)),
return;
for(c = sel->next; c && !isvisible(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags); c = c->next);
if(!c)
for(c = clients; c && !isvisible(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags); c = c->next);
for(c = *awesomeconf->clients; c && !isvisible(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags); c = c->next);
if(c)
{
focus(c->display, c, True, awesomeconf);
@ -85,7 +85,7 @@ uicb_focusprev(Display *disp __attribute__ ((unused)),
for(c = sel->prev; c && !isvisible(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags); c = c->prev);
if(!c)
{
for(c = clients; c && c->next; c = c->next);
for(c = *awesomeconf->clients; c && c->next; c = c->next);
for(; c && !isvisible(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags); c = c->prev);
}
if(c)
@ -137,7 +137,7 @@ restack(Display * disp, awesome_config *awesomeconf)
XConfigureWindow(disp, sel->win, CWSibling | CWStackMode, &wc);
wc.sibling = sel->win;
}
for(c = clients; c; c = c->next)
for(c = *awesomeconf->clients; c; c = c->next)
{
if(!IS_TILED(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags) || c == sel)
continue;
@ -189,7 +189,7 @@ uicb_setlayout(Display *disp,
awesomeconf->current_layout = &awesomeconf->layouts[i];
for(c = clients; c; c = c->next)
for(c = *awesomeconf->clients; c; c = c->next)
c->ftview = True;
if(sel)
@ -278,8 +278,8 @@ uicb_zoom(Display *disp __attribute__ ((unused)),
{
if(!sel)
return;
detach(sel);
attach(sel);
detach(awesomeconf->clients, sel);
attach(awesomeconf->clients, sel);
focus(sel->display, sel, True, awesomeconf);
arrange(sel->display, awesomeconf);
}

View File

@ -22,15 +22,12 @@
#include "tag.h"
#include "layouts/floating.h"
/* extern */
extern Client *clients; /* global client */
void
layout_floating(Display *disp __attribute__ ((unused)), awesome_config *awesomeconf)
{ /* default floating layout */
Client *c;
for(c = clients; c; c = c->next)
for(c = *awesomeconf->clients; c; c = c->next)
if(isvisible(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags))
{
if(c->ftview)

View File

@ -23,16 +23,13 @@
#include "screen.h"
#include "layouts/max.h"
/* extern */
extern Client *clients; /* global client */
void
layout_max(Display *disp, awesome_config *awesomeconf)
{
Client *c;
ScreenInfo *si = get_screen_info(disp, awesomeconf->screen, &awesomeconf->statusbar);
for(c = clients; c; c = c->next)
for(c = *awesomeconf->clients; c; c = c->next)
if(IS_TILED(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags))
resize(c, si[awesomeconf->screen].x_org, si[awesomeconf->screen].y_org,
si[awesomeconf->screen].width - 2 * c->border,

View File

@ -28,9 +28,6 @@
#include "layout.h"
#include "layouts/tile.h"
/* extern */
extern Client *clients;
void
uicb_setnmaster(Display *disp,
awesome_config *awesomeconf,
@ -104,7 +101,7 @@ _tile(Display *disp, awesome_config *awesomeconf, const Bool right)
screens_info = get_screen_info(disp, awesomeconf->screen, &awesomeconf->statusbar);
for(n = 0, c = clients; c; c = c->next)
for(n = 0, c = *awesomeconf->clients; c; c = c->next)
if(IS_TILED(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags))
n++;
@ -130,7 +127,7 @@ _tile(Display *disp, awesome_config *awesomeconf, const Bool right)
real_ncol = MIN(otherwin, awesomeconf->ncol);
for(i = 0, c = clients; c; c = c->next)
for(i = 0, c = *awesomeconf->clients; c; c = c->next)
{
if(!IS_TILED(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags))
continue;

View File

@ -24,7 +24,7 @@
#include "tag.h"
#include "layout.h"
extern Client *sel, *clients;
extern Client *sel;
/** Get screens info
* \param disp Display ref
@ -197,7 +197,7 @@ uicb_focusnextscreen(Display *disp,
Client *c;
int next_screen = awesomeconf->screen + 1 >= get_screen_count(disp) ? 0 : awesomeconf->screen + 1;
for(c = clients; c && !isvisible(c, next_screen, awesomeconf[next_screen - awesomeconf->screen].tags, awesomeconf[next_screen - awesomeconf->screen].ntags); c = c->next);
for(c = *awesomeconf->clients; c && !isvisible(c, next_screen, awesomeconf[next_screen - awesomeconf->screen].tags, awesomeconf[next_screen - awesomeconf->screen].ntags); c = c->next);
if(c)
{
focus(c->display, c, True, &awesomeconf[next_screen - awesomeconf->screen]);
@ -214,7 +214,7 @@ uicb_focusprevscreen(Display *disp,
Client *c;
int prev_screen = awesomeconf->screen - 1 < 0 ? get_screen_count(disp) - 1 : awesomeconf->screen - 1;
for(c = clients; c && !isvisible(c, prev_screen, awesomeconf[prev_screen - awesomeconf->screen].tags, awesomeconf[prev_screen - awesomeconf->screen].ntags); c = c->next);
for(c = *awesomeconf->clients; c && !isvisible(c, prev_screen, awesomeconf[prev_screen - awesomeconf->screen].tags, awesomeconf[prev_screen - awesomeconf->screen].ntags); c = c->next);
if(c)
{
focus(c->display, c, True, &awesomeconf[prev_screen - awesomeconf->screen]);

View File

@ -28,7 +28,7 @@
#include "util.h"
#include "layouts/tile.h"
extern Client *clients, *sel; /* global client list */
extern Client *sel;
/** Check if at least a client is tagged with tag number t and is on screen
* screen
@ -37,11 +37,11 @@ extern Client *clients, *sel; /* global client list */
* \return True or False
*/
static Bool
isoccupied(unsigned int t, int screen)
isoccupied(Client **head, unsigned int t, int screen)
{
Client *c;
for(c = clients; c; c = c->next)
for(c = *head; c; c = c->next)
if(c->tags[t] && c->screen == screen)
return True;
return False;
@ -67,7 +67,7 @@ drawstatusbar(Display *disp, awesome_config * awesomeconf)
awesomeconf->statusbar.height,
awesomeconf->font,
awesomeconf->tags[i].name, awesomeconf->colors_selected);
if(isoccupied(i, awesomeconf->screen))
if(isoccupied(awesomeconf->clients, i, awesomeconf->screen))
drawrectangle(disp, awesomeconf->phys_screen,
x, y,
(awesomeconf->font->height + 2) / 4,
@ -88,7 +88,7 @@ drawstatusbar(Display *disp, awesome_config * awesomeconf)
awesomeconf->statusbar.height,
awesomeconf->font,
awesomeconf->tags[i].name, awesomeconf->colors_normal);
if(isoccupied(i, awesomeconf->screen))
if(isoccupied(awesomeconf->clients, i, awesomeconf->screen))
drawrectangle(disp, awesomeconf->phys_screen,
x, y,
(awesomeconf->font->height + 2) / 4,