mirror of
https://github.com/0intro/wmii
synced 2025-03-01 20:51:25 +03:00
enumerized atoms
This commit is contained in:
parent
5ab0974e4a
commit
be62288596
@ -142,26 +142,26 @@ detach_fromarea(Client *c)
|
||||
}
|
||||
|
||||
char *
|
||||
colmode2str(ColumnMode mode)
|
||||
mode2str(int mode)
|
||||
{
|
||||
switch(mode) {
|
||||
case COL_EQUAL: return "equal"; break;
|
||||
case COL_STACK: return "stack"; break;
|
||||
case COL_MAX: return "max"; break;
|
||||
case Colequal: return "equal"; break;
|
||||
case Colstack: return "stack"; break;
|
||||
case Colmax: return "max"; break;
|
||||
default: break;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
ColumnMode
|
||||
str2colmode(char *arg)
|
||||
int
|
||||
str2mode(char *arg)
|
||||
{
|
||||
if(!strncmp("equal", arg, 6))
|
||||
return COL_EQUAL;
|
||||
return Colequal;
|
||||
if(!strncmp("stack", arg, 6))
|
||||
return COL_STACK;
|
||||
return Colstack;
|
||||
if(!strncmp("max", arg, 4))
|
||||
return COL_MAX;
|
||||
return Colmax;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -177,7 +177,7 @@ relax_area(Area *a)
|
||||
h = 0;
|
||||
for(i = 0; i < a->nclient; i++) {
|
||||
Client *c = a->client[i];
|
||||
if(a->mode == COL_MAX) {
|
||||
if(a->mode == Colmax) {
|
||||
if(h < c->frame.rect.height)
|
||||
h = c->frame.rect.height;
|
||||
}
|
||||
@ -186,7 +186,7 @@ relax_area(Area *a)
|
||||
}
|
||||
|
||||
/* try to add rest space to all clients if not COL_STACK mode */
|
||||
if(a->mode != COL_STACK) {
|
||||
if(a->mode != Colstack) {
|
||||
for(i = 0; (h < a->rect.height) && (i < a->nclient); i++) {
|
||||
Client *c = a->client[i];
|
||||
unsigned int tmp = c->frame.rect.height;
|
||||
@ -202,7 +202,7 @@ relax_area(Area *a)
|
||||
Client *c = a->client[i];
|
||||
c->frame.rect.x = a->rect.x + (a->rect.width - c->frame.rect.width) / 2;
|
||||
c->frame.rect.y = yoff;
|
||||
if(a->mode != COL_MAX)
|
||||
if(a->mode != Colmax)
|
||||
yoff = c->frame.rect.y + c->frame.rect.height + hdiff;
|
||||
resize_client(c, &c->frame.rect, 0, False);
|
||||
}
|
||||
@ -217,7 +217,7 @@ arrange_area(Area *a)
|
||||
return;
|
||||
|
||||
switch(a->mode) {
|
||||
case COL_EQUAL:
|
||||
case Colequal:
|
||||
h = a->rect.height;
|
||||
h /= a->nclient;
|
||||
for(i = 0; i < a->nclient; i++) {
|
||||
@ -232,7 +232,7 @@ arrange_area(Area *a)
|
||||
resize_client(c, &c->frame.rect, 0, True);
|
||||
}
|
||||
break;
|
||||
case COL_STACK:
|
||||
case Colstack:
|
||||
yoff = a->rect.y;
|
||||
h = a->rect.height - (a->nclient - 1) * bar_height();
|
||||
for(i = 0; i < a->nclient; i++) {
|
||||
@ -247,7 +247,7 @@ arrange_area(Area *a)
|
||||
resize_client(c, &c->frame.rect, 0, True);
|
||||
}
|
||||
break;
|
||||
case COL_MAX:
|
||||
case Colmax:
|
||||
for(i = 0; i < a->nclient; i++) {
|
||||
Client *c = a->client[i];
|
||||
c->frame.rect = a->rect;
|
||||
|
@ -70,8 +70,8 @@ set_client_state(Client * c, int state)
|
||||
|
||||
data[0] = (long) state;
|
||||
data[1] = (long) None;
|
||||
XChangeProperty(dpy, c->win, wm_state, wm_state, 32, PropModeReplace,
|
||||
(unsigned char *) data, 2);
|
||||
XChangeProperty(dpy, c->win, wm_atom[WMState], wm_atom[WMState], 32,
|
||||
PropModeReplace, (unsigned char *) data, 2);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -114,7 +114,7 @@ focus_client(Client *c)
|
||||
XSync(dpy, False);
|
||||
client_name_event(c);
|
||||
client_focus_event(c);
|
||||
if(i > 0 && c->area->mode == COL_STACK)
|
||||
if(i > 0 && c->area->mode == Colstack)
|
||||
arrange_area(c->area);
|
||||
}
|
||||
|
||||
@ -188,7 +188,7 @@ void
|
||||
kill_client(Client * c)
|
||||
{
|
||||
if(c->proto & PROTO_DEL)
|
||||
send_client_message(c->win, wm_protocols, wm_delete);
|
||||
send_client_message(c->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
|
||||
else
|
||||
XKillClient(dpy, c->win);
|
||||
}
|
||||
@ -199,7 +199,7 @@ handle_client_property(Client *c, XPropertyEvent *e)
|
||||
XTextProperty name;
|
||||
long msize;
|
||||
|
||||
if(e->atom == wm_protocols) {
|
||||
if(e->atom == wm_atom[WMProtocols]) {
|
||||
/* update */
|
||||
c->proto = win_proto(c->win);
|
||||
return;
|
||||
@ -477,14 +477,14 @@ resize_client(Client *c, XRectangle *r, XPoint *pt, Bool ignore_xcall)
|
||||
else
|
||||
c->frame.rect = *r;
|
||||
|
||||
if((c->area->mode != COL_STACK) || (c->area->sel == client2index(c)))
|
||||
if((c->area->mode != Colstack) || (c->area->sel == client2index(c)))
|
||||
match_sizehints(c, bh, bw);
|
||||
|
||||
if(!ignore_xcall)
|
||||
XMoveResizeWindow(dpy, c->frame.win, px - (pi * rect.width) + c->frame.rect.x, c->frame.rect.y,
|
||||
c->frame.rect.width, c->frame.rect.height);
|
||||
|
||||
if((c->area->mode != COL_STACK) || (c->area->sel == client2index(c))) {
|
||||
if((c->area->mode != Colstack) || (c->area->sel == client2index(c))) {
|
||||
c->rect.x = bw;
|
||||
c->rect.y = bh ? bh : bw;
|
||||
c->rect.width = c->frame.rect.width - 2 * bw;
|
||||
|
@ -292,9 +292,9 @@ static void handle_clientmessage(XEvent *e)
|
||||
XClientMessageEvent *ev = &e->xclient;
|
||||
Client *c;
|
||||
|
||||
if (ev->message_type == net_atoms[NET_NUMBER_OF_DESKTOPS] && ev->format == 32)
|
||||
if (ev->message_type == net_atom[NetNumWS] && ev->format == 32)
|
||||
return; /* ignore */
|
||||
else if (ev->message_type == net_atoms[NET_CURRENT_DESKTOP] && ev->format == 32) {
|
||||
else if (ev->message_type == net_atom[NetSelWS] && ev->format == 32) {
|
||||
int i = ev->data.l[0];
|
||||
if(i < ntag) {
|
||||
Tag *p = tag[i];
|
||||
|
27
cmd/wm/fs.c
27
cmd/wm/fs.c
@ -562,7 +562,7 @@ type2stat(Stat *stat, char *wname, Qid *dir)
|
||||
return mkstat(stat, dir, wname, (dir_i1 == nlabel) ? 0 : strlen(label[dir_i1]->data), DMREAD | DMWRITE);
|
||||
break;
|
||||
case Fmode:
|
||||
return mkstat(stat, dir, wname, strlen(colmode2str(tag[dir_i1]->area[dir_i2]->mode)), DMREAD | DMWRITE);
|
||||
return mkstat(stat, dir, wname, strlen(mode2str(tag[dir_i1]->area[dir_i2]->mode)), DMREAD | DMWRITE);
|
||||
break;
|
||||
case Fcolors:
|
||||
case Fselcolors:
|
||||
@ -951,7 +951,7 @@ xread(IXPConn *c, Fcall *fcall)
|
||||
case Fmode:
|
||||
if(!i2)
|
||||
return Enofile;
|
||||
snprintf(buf, sizeof(buf), "%s", colmode2str(tag[i1]->area[i2]->mode));
|
||||
snprintf(buf, sizeof(buf), "%s", mode2str(tag[i1]->area[i2]->mode));
|
||||
fcall->count = strlen(buf);
|
||||
memcpy(p, buf, fcall->count);
|
||||
break;
|
||||
@ -986,9 +986,8 @@ xwrite(IXPConn *c, Fcall *fcall)
|
||||
{
|
||||
char buf[256];
|
||||
IXPMap *m = ixp_server_fid2map(c, fcall->fid);
|
||||
unsigned short i;
|
||||
unsigned char type;
|
||||
int i1 = 0, i2 = 0, i3 = 0;
|
||||
int i, i1 = 0, i2 = 0, i3 = 0;
|
||||
Client *cl;
|
||||
|
||||
if(!m)
|
||||
@ -1145,18 +1144,14 @@ xwrite(IXPConn *c, Fcall *fcall)
|
||||
resize_all_clients();
|
||||
break;
|
||||
case Fmode:
|
||||
{
|
||||
ColumnMode mode;
|
||||
if(!i2)
|
||||
return Enofile;
|
||||
memcpy(buf, fcall->data, fcall->count);
|
||||
buf[fcall->count] = 0;
|
||||
mode = str2colmode(buf);
|
||||
if(mode == -1)
|
||||
return "invalid area mode";
|
||||
tag[i1]->area[i2]->mode = mode;
|
||||
arrange_area(tag[i1]->area[i2]);
|
||||
}
|
||||
if(!i2)
|
||||
return Enofile;
|
||||
memcpy(buf, fcall->data, fcall->count);
|
||||
buf[fcall->count] = 0;
|
||||
if((i = str2mode(buf)) == -1)
|
||||
return "invalid area mode";
|
||||
tag[i1]->area[i2]->mode = i;
|
||||
arrange_area(tag[i1]->area[i2]);
|
||||
break;
|
||||
case Fkey:
|
||||
break;
|
||||
|
@ -22,7 +22,7 @@ alloc_tag()
|
||||
tag = (Tag **)cext_array_attach((void **)tag, t, sizeof(Tag *), &tagsz);
|
||||
ntag++;
|
||||
focus_tag(t);
|
||||
XChangeProperty(dpy, root, net_atoms[NET_NUMBER_OF_DESKTOPS], XA_CARDINAL,
|
||||
XChangeProperty(dpy, root, net_atom[NetNumWS], XA_CARDINAL,
|
||||
32, PropModeReplace, (unsigned char *) &ntag, 1);
|
||||
return t;
|
||||
}
|
||||
@ -47,7 +47,7 @@ destroy_tag(Tag *t)
|
||||
for(i = 0; i < ntag; i++) {
|
||||
if(tag[i]->revert == t)
|
||||
tag[i]->revert = nil;
|
||||
XChangeProperty(dpy, root, net_atoms[NET_NUMBER_OF_DESKTOPS], XA_CARDINAL,
|
||||
XChangeProperty(dpy, root, net_atom[NetNumWS], XA_CARDINAL,
|
||||
32, PropModeReplace, (unsigned char *) &i, 1);
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ focus_tag(Tag *t)
|
||||
}
|
||||
snprintf(buf, sizeof(buf), "PN %d\n", sel);
|
||||
write_event(buf);
|
||||
XChangeProperty(dpy, root, net_atoms[NET_CURRENT_DESKTOP], XA_CARDINAL,
|
||||
XChangeProperty(dpy, root, net_atom[NetSelWS], XA_CARDINAL,
|
||||
32, PropModeReplace, (unsigned char *) &sel, 1);
|
||||
XSync(dpy, False);
|
||||
}
|
||||
|
27
cmd/wm/wm.c
27
cmd/wm/wm.c
@ -96,15 +96,14 @@ win_proto(Window w)
|
||||
int protos = 0;
|
||||
int i;
|
||||
|
||||
res = win_property(w, wm_protocols, XA_ATOM, 20L,
|
||||
res = win_property(w, wm_atom[WMProtocols], XA_ATOM, 20L,
|
||||
((unsigned char **) &protocols));
|
||||
if(res <= 0) {
|
||||
return protos;
|
||||
}
|
||||
for(i = 0; i < res; i++) {
|
||||
if(protocols[i] == wm_delete) {
|
||||
if(protocols[i] == wm_atom[WMDelete])
|
||||
protos |= PROTO_DEL;
|
||||
}
|
||||
}
|
||||
free((char *) protocols);
|
||||
return protos;
|
||||
@ -118,8 +117,9 @@ win_state(Window w)
|
||||
int res;
|
||||
|
||||
long *prop = 0;
|
||||
if(win_property(w, wm_state, wm_state, 2L,
|
||||
((unsigned char **) &prop)) > 0) {
|
||||
if(win_property(w, wm_atom[WMState], wm_atom[WMState], 2L,
|
||||
((unsigned char **) &prop)) > 0)
|
||||
{
|
||||
res = (int) *prop;
|
||||
free((long *) prop);
|
||||
} else {
|
||||
@ -135,15 +135,14 @@ win_state(Window w)
|
||||
static void
|
||||
init_atoms()
|
||||
{
|
||||
wm_state = XInternAtom(dpy, "WM_STATE", False);
|
||||
wm_change_state = XInternAtom(dpy, "WM_CHANGE_STATE", False);
|
||||
wm_protocols = XInternAtom(dpy, "WM_PROTOCOLS", False);
|
||||
wm_delete = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
|
||||
motif_wm_hints = XInternAtom(dpy, "_MOTIF_WM_HINTS", False);
|
||||
net_atoms[NET_NUMBER_OF_DESKTOPS] = XInternAtom(dpy, "_NET_NUMBER_OF_DESKTOPS", False);
|
||||
net_atoms[NET_CURRENT_DESKTOP] = XInternAtom(dpy, "_NET_CURRENT_DESKTOP", False);
|
||||
net_atoms[NET_WM_DESKTOP] = XInternAtom(dpy, "_NET_WM_DESKTOP", False);
|
||||
XChangeProperty(dpy, root, XInternAtom(dpy, "_NET_SUPPORTED", False), XA_ATOM, 32, PropModeReplace, (unsigned char *) net_atoms, NET_ATOM_COUNT);
|
||||
wm_atom[WMState] = XInternAtom(dpy, "WM_STATE", False);
|
||||
wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
|
||||
wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
|
||||
net_atom[NetNumWS] = XInternAtom(dpy, "_NET_NUMBER_OF_DESKTOPS", False);
|
||||
net_atom[NetSelWS] = XInternAtom(dpy, "_NET_CURRENT_DESKTOP", False);
|
||||
net_atom[NetWS] = XInternAtom(dpy, "_NET_WM_DESKTOP", False);
|
||||
XChangeProperty(dpy, root, XInternAtom(dpy, "_NET_SUPPORTED", False), XA_ATOM, 32,
|
||||
PropModeReplace, (unsigned char *) net_atom, NetLast);
|
||||
}
|
||||
|
||||
static void
|
||||
|
42
cmd/wm/wm.h
42
cmd/wm/wm.h
@ -10,12 +10,25 @@
|
||||
#include "ixp.h"
|
||||
#include "blitz.h"
|
||||
|
||||
/* array indexes of EWMH window properties */
|
||||
/* TODO: set / react */
|
||||
/* array indexes of atoms */
|
||||
enum {
|
||||
NET_NUMBER_OF_DESKTOPS, /* ✓ – */
|
||||
NET_CURRENT_DESKTOP, /* ✓ ✓ */
|
||||
NET_WM_DESKTOP /* ✗ ✗ */
|
||||
WMState,
|
||||
WMProtocols,
|
||||
WMDelete,
|
||||
WMLast
|
||||
};
|
||||
|
||||
enum {
|
||||
NetNumWS,
|
||||
NetSelWS,
|
||||
NetWS,
|
||||
NetLast
|
||||
};
|
||||
|
||||
enum {
|
||||
Colequal,
|
||||
Colstack,
|
||||
Colmax
|
||||
};
|
||||
|
||||
/* 8-bit qid.path.type */
|
||||
@ -45,12 +58,9 @@ enum {
|
||||
Fmode
|
||||
};
|
||||
|
||||
#define NET_ATOM_COUNT 3
|
||||
|
||||
#define PROTO_DEL 1
|
||||
#define DEF_BORDER 3
|
||||
#define DEF_SNAP 20
|
||||
#define DEF_PAGER_GAP 5
|
||||
|
||||
#define ROOT_MASK SubstructureRedirectMask
|
||||
#define CLIENT_MASK (StructureNotifyMask | PropertyChangeMask)
|
||||
@ -59,7 +69,6 @@ typedef struct Area Area;
|
||||
typedef struct Tag Tag;
|
||||
typedef struct Client Client;
|
||||
|
||||
typedef enum { COL_EQUAL, COL_STACK, COL_MAX, COL_MODE_LAST } ColumnMode;
|
||||
|
||||
struct Area {
|
||||
unsigned short id;
|
||||
@ -68,7 +77,7 @@ struct Area {
|
||||
unsigned int clientsz;
|
||||
unsigned int sel;
|
||||
unsigned int nclient;
|
||||
ColumnMode mode;
|
||||
int mode;
|
||||
XRectangle rect;
|
||||
};
|
||||
|
||||
@ -161,13 +170,8 @@ XRectangle brect;
|
||||
Qid root_qid;
|
||||
|
||||
Default def;
|
||||
|
||||
Atom wm_state; /* TODO: Maybe replace with wm_atoms[WM_ATOM_COUNT]? */
|
||||
Atom wm_change_state;
|
||||
Atom wm_protocols;
|
||||
Atom wm_delete;
|
||||
Atom motif_wm_hints;
|
||||
Atom net_atoms[NET_ATOM_COUNT];
|
||||
Atom wm_atom[WMLast];
|
||||
Atom net_atom[NetLast];
|
||||
|
||||
Cursor normal_cursor;
|
||||
Cursor resize_cursor;
|
||||
@ -198,8 +202,8 @@ void arrange_tag(Tag *t, Bool updategeometry);
|
||||
void arrange_area(Area *a);
|
||||
void resize_area(Client *c, XRectangle *r, XPoint *pt);
|
||||
Area *new_area(Tag *t);
|
||||
ColumnMode str2colmode(char *arg);
|
||||
char *colmode2str(ColumnMode mode);
|
||||
int str2mode(char *arg);
|
||||
char *mode2str(int mode);
|
||||
|
||||
/* bar.c */
|
||||
Label *new_label();
|
||||
|
Loading…
x
Reference in New Issue
Block a user