int flags, x, w;
} Column;
-struct {
+static struct {
Node *floated, *tiled;
} Desktops[10] = {{0},{0},{0},{0},{0},{0},{0},{0},{0},{0}};
-int Desktop = 1;
+static int Desktop = 1;
XConf X = {0};
-Node* All_Clients = NULL;
-Cursor Move_Cursor;
-Cursor Main_Cursor;
-int StartY = 0;
+static Node* All_Clients = NULL;
+static Cursor Move_Cursor;
+static Cursor Main_Cursor;
+static int StartY = 0;
/* configuration */
-uint32_t BorderWidth = 1;
-uint32_t BorderColor = 0xFF0000;
-uint32_t BackgroundColor = 0x000077;
+static uint32_t BorderWidth = 1;
+static uint32_t BorderColor = 0xFF0000;
+static uint32_t BackgroundColor = 0x000077;
-Atom
+static Atom
XA_NET_WM_WINDOW_TYPE,
XA_NET_WM_WINDOW_TYPE_DIALOG,
XA_WM_PROTOCOLS;
const Arg arg;
};
-void change_desktop(const Arg arg);
-void client_to_desktop(const Arg arg);
+static void change_desktop(const Arg arg);
+static void client_to_desktop(const Arg arg);
#define MOD Mod1Mask
#define DESKTOPCHANGE(K,N) \
/* Utility Functions
*****************************************************************************/
-void die(char* errstr) {
+static void die(char* errstr) {
fprintf(stderr, "error: %s\n", errstr);
exit(1);
}
-Atom atom(XConf* x, char* s) {
+static Atom atom(XConf* x, char* s) {
return XInternAtom(x->display, s, False);
}
-void* xfree(void* p) {
+static void* xfree(void* p) {
if (p) XFree(p);
return NULL;
}
-int get_prop(XConf* x, Window w, Atom name, Atom* type, int* format, void** data, size_t* ndata) {
+static int get_prop(XConf* x, Window w, Atom name, Atom* type, int* format, void** data, size_t* ndata) {
unsigned long nleft;
return XGetWindowProperty(
x->display, w, name, 0, -1, False, AnyPropertyType, type, format, ndata, &nleft, (unsigned char**)data);
/* List Handling
*****************************************************************************/
-void list_add(Node** list, Node* parent, Node* node) {
+static void list_add(Node** list, Node* parent, Node* node) {
if (!parent) {
node->next = *list;
+ node->prev = NULL;
if (*list) (*list)->prev = node;
*list = node;
} else {
}
}
-void list_del(Node** list, Node* node) {
+static void list_del(Node** list, Node* node) {
if (node->prev) node->prev->next = node->next;
if (node->next) node->next->prev = node->prev;
+ node->next = NULL, node->prev = NULL;
if (*list == node) *list = node->next;
}
-void* list_reduce(Node* list, Reducer rfn, void* accum) {
+static void* list_reduce(Node* list, Reducer rfn, void* accum) {
return (list ? list_reduce(list->next, rfn, rfn(list, accum)) : accum);
}
-size_t list_count(Node* curr) {
+static size_t list_count(Node* curr) {
size_t nclients = 0;
for (; curr; curr = curr->next, nclients++);
return nclients;
/* Client Handling
*****************************************************************************/
-void client_reconfig(XConf* xs, Client* c);
-void client_config(XConf* xs, Client* c, int x, int y, int w, int h);
+static void client_reconfig(XConf* xs, Client* c);
+static void client_config(XConf* xs, Client* c, int x, int y, int w, int h);
-void* biggest(Node* node, void* accum) {
+static void* biggest(Node* node, void* accum) {
if (!accum || TCLIENT(node)->h > ((Client*)accum)->h)
accum = TCLIENT(node);
return accum;
}
-void* find_win(Node* n, void* env) {
+static void* find_win(Node* n, void* env) {
struct { Window w; Client* c; }* state = env;
if ((MCLIENT(n)->frame == state->w) || (MCLIENT(n)->win == state->w))
state->c = MCLIENT(n);
return env;
}
-void* grow_client(Node* node, void* env) {
+static void* grow_client(Node* node, void* env) {
GrowState* state = env;
Client* curr = TCLIENT(node);
state->nclients--;
return state;
}
-int client_flags(Client* c, int mask) {
+static int client_flags(Client* c, int mask) {
return (c->flags & mask);
}
-void client_raise(XConf* x, Client* c) {
- XMapRaised(x->display, c->frame);
- XMapRaised(x->display, c->win);
+static void client_raise(XConf* x, Client* c) {
+ XMapWindow(x->display, c->frame);
+ XMapWindow(x->display, c->win);
+ if (!client_flags(c, FLOATING)) {
+ XLowerWindow(x->display, c->frame);
+ XLowerWindow(x->display, c->win);
+ } else {
+ XRaiseWindow(x->display, c->frame);
+ XRaiseWindow(x->display, c->win);
+ }
+ XSync(x->display, False);
}
-void client_add(Client* c, int dtop) {
+static void client_add(Client* c, int dtop) {
list_add(&All_Clients, NULL, &(c->mnode));
if (!client_flags(c, FLOATING)) {
Client* parent = list_reduce(Desktops[dtop].tiled, biggest, NULL);
}
}
-void client_del(Client* c) {
+static void client_del(Client* c) {
list_del(&All_Clients, &(c->mnode));
if (!client_flags(c, FLOATING)) {
list_del(&Tiled_Clients, &(c->tnode));
}
}
-void client_redraw(XConf* x, Client* c) {
- puts("redraw");
+static void client_redraw(XConf* x, Client* c) {
XftColor fgclr, bgclr;
if (!c->name) return;
xftcolor(x, &fgclr, -1);
XftColorFree(x->display, x->visual, x->colormap, &bgclr);
}
-void client_reconfig(XConf* xs, Client* c) {
+static void client_reconfig(XConf* xs, Client* c) {
int height = BARHEIGHT(xs);
XMoveResizeWindow(xs->display, c->frame, c->x, c->y, c->w - 2, height);
if (c->h <= height) {
XSync(xs->display, False);
}
-void client_config(XConf* xs, Client* c, int x, int y, int w, int h) {
+static void client_config(XConf* xs, Client* c, int x, int y, int w, int h) {
c->x = x, c->y = y, c->w = w, c->h = h;
client_reconfig(xs, c);
client_redraw(xs, c);
}
-void client_initprops(XConf* x, Client* c) {
+static void client_initprops(XConf* x, Client* c) {
int nprops = 0;
Atom* props = XListProperties(x->display, c->win, &nprops);
Atom type;
}
}
-void client_create(XConf* x, Window win) {
+static void client_create(XConf* x, Window win) {
Client* c = calloc(1, sizeof(Client));
c->win = win;
XGrabServer(x->display);
XUngrabServer(x->display);
}
-void client_destroy(XConf* x, Client* c) {
+static void client_destroy(XConf* x, Client* c) {
client_del(c);
XGrabServer(x->display);
XftDrawDestroy(c->xft);
XUngrabServer(x->display);
}
-Client* client_find(Window win) {
+static Client* client_find(Window win) {
struct { Window w; Client* c; } state = { .w = win };
list_reduce(All_Clients, find_win, &state);
return state.c;
}
-void client_resize(XConf* x, Client* c, int dir) {
+static void client_resize(XConf* x, Client* c, int dir) {
(void)x, (void)c, (void)dir;
if (!c->tnode.prev) return;
Client* prev = TCLIENT(c->tnode.prev);
client_reconfig(x, c);
}
-void client_grow(XConf* x, Client* c) {
+static void client_grow(XConf* x, Client* c) {
GrowState state = {
.c = c,
.nclients = list_count(Tiled_Clients),
list_reduce(Tiled_Clients, grow_client, &state);
}
-void client_maximize(XConf* xs, Client* c) {
+static void client_maximize(XConf* xs, Client* c) {
int y = c->y, h = c->h;
c->y = 0, c->h = HeightOfScreen(DefaultScreenOfDisplay(xs->display));
client_reconfig(xs, c);
/* Desktop Management
*****************************************************************************/
-void* hide_wins(Node* node, void* data) {
+static void* hide_wins(Node* node, void* data) {
Client* c = TCLIENT(node);
XUnmapWindow(X.display, c->frame);
XUnmapWindow(X.display, c->win);
return data;
}
-void* show_wins(Node* node, void* data) {
+static void* show_wins(Node* node, void* data) {
Client* c = TCLIENT(node);
XMapWindow(X.display, c->frame);
XMapWindow(X.display, c->win);
return data;
}
-void change_desktop(const Arg arg) {
+static void change_desktop(const Arg arg) {
XGrabServer(X.display);
list_reduce(Tiled_Clients, hide_wins, NULL);
list_reduce(Floated_Clients, hide_wins, NULL);
list_reduce(Tiled_Clients, show_wins, NULL);
list_reduce(Floated_Clients, show_wins, NULL);
XUngrabServer(X.display);
- XSync(X.display, True);
+ XSync(X.display, False);
}
-void client_to_desktop(const Arg arg) {
+static void client_to_desktop(const Arg arg) {
int bar;
Window foo, win;
do{
client_del(c);
XUnmapWindow(X.display, c->frame);
XUnmapWindow(X.display, c->win);
- XSync(X.display, True);
+ XSync(X.display, False);
client_add(c, arg.i);
}