Merge branch 'personal'

Conflicts:
	config.h
This commit is contained in:
seanpringle
2012-10-25 02:21:26 +10:00
7 changed files with 128 additions and 152 deletions

View File

@@ -40,12 +40,12 @@ void action_move_direction(void *data, int num, client *cli)
void action_focus(void *data, int num, client *cli) void action_focus(void *data, int num, client *cli)
{ {
spot_focus_top_window(num, current_mon, None); spot_try_focus_top_window(num, current_mon, None);
} }
void action_focus_direction(void *data, int num, client *cli) void action_focus_direction(void *data, int num, client *cli)
{ {
spot_focus_top_window(spot_choose_by_direction(current_spot, current_mon, num), current_mon, None); spot_try_focus_top_window(spot_choose_by_direction(current_spot, current_mon, num), current_mon, None);
} }
void action_close(void *data, int num, client *cli) void action_close(void *data, int num, client *cli)
@@ -123,8 +123,7 @@ void action_above(void *data, int num, client *cli)
void action_snapshot(void *data, int num, client *cli) void action_snapshot(void *data, int num, client *cli)
{ {
int i; client *c; int i; client *c; STACK_FREE(&snapshot);
STACK_FREE(&snapshot);
for_windows(i, c) if (c->manage && c->class) for_windows(i, c) if (c->manage && c->class)
snapshot.clients[snapshot.depth++] = window_build_client(c->window); snapshot.clients[snapshot.depth++] = window_build_client(c->window);
} }
@@ -146,6 +145,7 @@ void action_rollback(void *data, int num, client *cli)
} }
} }
client_free(c); client_free(c);
c = NULL;
} }
if (a) if (a)
{ {

View File

@@ -62,9 +62,7 @@ client* window_build_client(Window win)
if (XGetWindowAttributes(display, c->window, &c->attr)) if (XGetWindowAttributes(display, c->window, &c->attr))
{ {
c->visible = c->attr.map_state == IsViewable ? 1:0; c->visible = c->attr.map_state == IsViewable ? 1:0;
XGetTransientForHint(display, c->window, &c->transient);
if (!GETPROP_ATOM(win, atoms[_NET_WM_WINDOW_TYPE], &c->type, 1)) c->type = 0; if (!GETPROP_ATOM(win, atoms[_NET_WM_WINDOW_TYPE], &c->type, 1)) c->type = 0;
if (!GETPROP_WIND(win, atoms[WM_CLIENT_LEADER], &c->leader, 1)) c->leader = None;
c->manage = !c->attr.override_redirect c->manage = !c->attr.override_redirect
&& c->type != atoms[_NET_WM_WINDOW_TYPE_DESKTOP] && c->type != atoms[_NET_WM_WINDOW_TYPE_DESKTOP]
@@ -73,40 +71,43 @@ client* window_build_client(Window win)
&& c->type != atoms[_NET_WM_WINDOW_TYPE_SPLASH] && c->type != atoms[_NET_WM_WINDOW_TYPE_SPLASH]
? 1:0; ? 1:0;
c->spot = SPOT1; m = &monitors[0]; for_monitors(i, m) for_spots(j)
if (m->bars[j] && m->bars[j]->window == c->window)
for_monitors(i, m) { c->ours = 1; c->manage = 0; break; }
if (INTERSECT(m->x, m->y, m->w, m->h, c->attr.x + c->attr.width/2, c->attr.y+c->attr.height/2, 1, 1))
{ c->monitor = i; break; }
for_spots_rev(i)
if (INTERSECT(m->spots[i].x, m->spots[i].y, m->spots[i].w, m->spots[i].h,
c->attr.x + c->attr.width/2, c->attr.y+c->attr.height/2, 1, 1))
{ c->spot = i; break; }
if (c->manage) if (c->manage)
for_monitors(i, m) for_spots(j)
if (m->bars[j] && m->bars[j]->window == c->window)
c->manage = 0;
if (c->visible)
{ {
if (!GETPROP_ATOM(c->window, atoms[_NET_WM_STATE], c->states, ATOMLIST)) XGetTransientForHint(display, c->window, &c->transient);
memset(c->states, 0, sizeof(Atom) * ATOMLIST); if (!GETPROP_WIND(win, atoms[WM_CLIENT_LEADER], &c->leader, 1)) c->leader = None;
c->urgent = client_has_state(c, atoms[_NET_WM_STATE_DEMANDS_ATTENTION]); c->spot = SPOT1; m = &monitors[0];
c->full = client_has_state(c, atoms[_NET_WM_STATE_FULLSCREEN]);
c->above = client_has_state(c, atoms[_NET_WM_STATE_ABOVE]);
if ((hints = XGetWMHints(display, c->window))) for_monitors(i, m)
if (INTERSECT(m->x, m->y, m->w, m->h, c->attr.x + c->attr.width/2, c->attr.y+c->attr.height/2, 1, 1))
{ c->monitor = i; break; }
for_spots_rev(i)
if (INTERSECT(m->spots[i].x, m->spots[i].y, m->spots[i].w, m->spots[i].h, c->attr.x + c->attr.width/2, c->attr.y+c->attr.height/2, 1, 1))
{ c->spot = i; break; }
if (c->visible)
{ {
c->input = hints->flags & InputHint && hints->input ? 1:0; if (!GETPROP_ATOM(c->window, atoms[_NET_WM_STATE], c->states, ATOMLIST))
c->urgent = c->urgent || hints->flags & XUrgencyHint ? 1:0; memset(c->states, 0, sizeof(Atom) * ATOMLIST);
XFree(hints); c->urgent = client_has_state(c, atoms[_NET_WM_STATE_DEMANDS_ATTENTION]);
} c->full = client_has_state(c, atoms[_NET_WM_STATE_FULLSCREEN]);
if (XGetClassHint(display, c->window, &chint)) c->above = client_has_state(c, atoms[_NET_WM_STATE_ABOVE]);
{
c->class = strdup(chint.res_class); if ((hints = XGetWMHints(display, c->window)))
XFree(chint.res_class); XFree(chint.res_name); {
c->input = hints->flags & InputHint && hints->input ? 1:0;
c->urgent = c->urgent || hints->flags & XUrgencyHint ? 1:0;
XFree(hints);
}
if (XGetClassHint(display, c->window, &chint))
{
c->class = strdup(chint.res_class);
XFree(chint.res_class); XFree(chint.res_name);
}
} }
} }
return c; return c;

19
event.c
View File

@@ -135,22 +135,21 @@ void key_press(XEvent *ev)
client *cli = window_build_client(current); client *cli = window_build_client(current);
bind->act(bind->data, bind->num, cli); bind->act(bind->data, bind->num, cli);
client_free(cli); client_free(cli);
update_bars();
} }
} }
void button_press(XEvent *ev) void button_press(XEvent *ev)
{ {
int i, j; monitor *m;
XButtonEvent *e = &ev->xbutton; latest = e->time; XButtonEvent *e = &ev->xbutton; latest = e->time;
client *c = window_build_client(e->subwindow); client *c = window_build_client(e->subwindow);
if (c && c->manage) if (c && c->manage)
client_activate(c); client_activate(c);
else else
{
int i, j; monitor *m;
for_monitors(i, m) for_spots(j) for_monitors(i, m) for_spots(j)
if (m->bars[j]->window == e->subwindow) if (m->bars[j]->window == e->subwindow)
spot_focus_top_window(j, i, None); spot_focus_top_window(j, i, None);
}
client_free(c); client_free(c);
XAllowEvents(display, ReplayPointer, CurrentTime); XAllowEvents(display, ReplayPointer, CurrentTime);
} }
@@ -183,17 +182,15 @@ void property_notify(XEvent *ev)
client *c = window_build_client(e->window); client *c = window_build_client(e->window);
if (c && c->visible && c->manage) if (c && c->visible && c->manage)
{
client_update_border(c); client_update_border(c);
if (e->atom == atoms[WM_NAME] || e->atom == atoms[_NET_WM_NAME])
spot_update_bar(c->spot, c->monitor);
}
client_free(c); client_free(c);
if (e->atom == atoms[WM_NAME] || e->atom == atoms[_NET_WM_NAME]) // prevent spam
update_bars(); while (XCheckTypedWindowEvent(display, ev->xproperty.window, PropertyNotify, ev));
// clients that rapidly update stuff (eg, title) can spam events.
// consume as many as possible of the same window, type, and atom...
Atom atom = e->atom;
while (XCheckTypedWindowEvent(display, ev->xproperty.window, PropertyNotify, ev))
if (ev->xproperty.atom != atom) { XPutBackEvent(display, ev); break; }
} }
void expose(XEvent *e) void expose(XEvent *e)

56
setup.c
View File

@@ -25,16 +25,13 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
typedef struct { typedef struct {
long left, right, top, bottom, // _NET_WM_STRUT_PARTIAL
ly1, ly2, ry1, ry3, long left, right, top, bottom, ly1, ly2, ry1, ry3, tx1, tx2, bx1, bx2;
tx1, tx2, bx1, bx2;
} wm_strut; } wm_strut;
void setup() void setup()
{ {
int i, j; client *c; monitor *m; int i, j; client *c; monitor *m;
wm_strut struts; memset(&struts, 0, sizeof(wm_strut));
int screen_w = WidthOfScreen(DefaultScreenOfDisplay(display)); int screen_w = WidthOfScreen(DefaultScreenOfDisplay(display));
int screen_h = HeightOfScreen(DefaultScreenOfDisplay(display)); int screen_h = HeightOfScreen(DefaultScreenOfDisplay(display));
@@ -58,6 +55,9 @@ void setup()
} }
// detect and adjust for panel struts // detect and adjust for panel struts
monitor padded[MONITORS];
memmove(padded, monitors, sizeof(monitor) * MONITORS);
for_windows(i, c) for_windows(i, c)
{ {
wm_strut strut; memset(&strut, 0, sizeof(wm_strut)); wm_strut strut; memset(&strut, 0, sizeof(wm_strut));
@@ -67,6 +67,8 @@ void setup()
for_monitors(j, m) for_monitors(j, m)
{ {
monitor *p = &padded[j];
// convert _NET_WM_STRUT to _PARTIAL
if (v1) if (v1)
{ {
strut.ly1 = m->y; strut.ly2 = m->y + m->h; strut.ly1 = m->y; strut.ly2 = m->y + m->h;
@@ -74,30 +76,37 @@ void setup()
strut.tx1 = m->x; strut.tx2 = m->x + m->w; strut.tx1 = m->x; strut.tx2 = m->x + m->w;
strut.bx1 = m->x; strut.bx2 = m->x + m->w; strut.bx1 = m->x; strut.bx2 = m->x + m->w;
} }
// monitor left side of root window?
if (strut.left > 0 && !m->x if (strut.left > 0 && !m->x
&& INTERSECT(0, strut.ly1, strut.left, strut.ly2 - strut.ly1, m->x, m->y, m->w, m->h)) && INTERSECT(0, strut.ly1, strut.left, strut.ly2 - strut.ly1, m->x, m->y, m->w, m->h))
{ {
m->x += strut.left; p->x = MAX(p->x, strut.left);
m->w -= strut.left; p->w = MIN(p->w, m->x + m->w - strut.left);
} }
else
// monitor right side of root window?
if (strut.right > 0 && m->x + m->w == screen_w if (strut.right > 0 && m->x + m->w == screen_w
&& INTERSECT(screen_w - strut.right, strut.ry1, strut.right, strut.ry3 - strut.ry1, m->x, m->y, m->w, m->h)) && INTERSECT(screen_w - strut.right, strut.ry1, strut.right, strut.ry3 - strut.ry1, m->x, m->y, m->w, m->h))
{ {
m->w -= strut.right; p->w = MIN(p->w, m->x + m->w - strut.right);
} }
// monitor top side of root window?
if (strut.top > 0 && !m->y if (strut.top > 0 && !m->y
&& INTERSECT(strut.tx1, 0, strut.tx2 - strut.tx1, strut.top, m->x, m->y, m->w, m->h)) && INTERSECT(strut.tx1, 0, strut.tx2 - strut.tx1, strut.top, m->x, m->y, m->w, m->h))
{ {
m->y += strut.top; p->y = MAX(p->y, strut.top);
m->h -= strut.top; p->h = MIN(p->h, m->y + m->h - strut.top);
} }
else
// monitor bottom side of root window?
if (strut.bottom > 0 && m->y + m->h == screen_h if (strut.bottom > 0 && m->y + m->h == screen_h
&& INTERSECT(strut.bx1, screen_h - strut.bottom, strut.bx2 - strut.bx1, strut.bottom, m->x, m->y, m->w, m->h)) && INTERSECT(strut.bx1, screen_h - strut.bottom, strut.bx2 - strut.bx1, strut.bottom, m->x, m->y, m->w, m->h))
{ {
m->h -= strut.bottom; p->h = MIN(p->h, m->y + m->h - strut.bottom);
} }
} }
} }
memmove(monitors, padded, sizeof(monitor) * MONITORS);
// calculate spot boxes // calculate spot boxes
for_monitors(i, m) for_monitors(i, m)
@@ -126,6 +135,7 @@ void setup()
} }
continue; continue;
} }
// normal wide screen
int width_spot1 = (double)w / 100 * MIN(90, MAX(10, SPOT1_WIDTH_PCT)); int width_spot1 = (double)w / 100 * MIN(90, MAX(10, SPOT1_WIDTH_PCT));
int height_spot2 = (double)h / 100 * MIN(90, MAX(10, SPOT2_HEIGHT_PCT)); int height_spot2 = (double)h / 100 * MIN(90, MAX(10, SPOT2_HEIGHT_PCT));
for_spots(j) for_spots(j)
@@ -161,10 +171,9 @@ void setup()
// figure out NumlockMask // figure out NumlockMask
XModifierKeymap *modmap = XGetModifierMapping(display); XModifierKeymap *modmap = XGetModifierMapping(display);
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++) for (j = 0; j < (int)modmap->max_keypermod; j++)
for (j = 0; j < (int)modmap->max_keypermod; j++) if (modmap->modifiermap[i*modmap->max_keypermod+j] == XKeysymToKeycode(display, XK_Num_Lock))
if (modmap->modifiermap[i*modmap->max_keypermod+j] == XKeysymToKeycode(display, XK_Num_Lock)) { NumlockMask = (1<<i); break; }
{ NumlockMask = (1<<i); break; }
XFreeModifiermap(modmap); XFreeModifiermap(modmap);
// process config.h key bindings // process config.h key bindings
@@ -184,18 +193,15 @@ void setup()
// create title bars // create title bars
STACK_FREE(&windows); STACK_FREE(&windows);
for_monitors(i, m) for_monitors(i, m) for_spots(j)
{ {
for_spots(j) m->bars[j] = textbox_create(root, TB_AUTOHEIGHT|TB_LEFT, m->spots[j].x, m->spots[j].y, m->spots[j].w, 0,
{ TITLE, TITLE_BLUR, BORDER_BLUR, NULL, NULL);
m->bars[j] = textbox_create(root, TB_AUTOHEIGHT|TB_LEFT, m->spots[j].x, m->spots[j].y, m->spots[j].w, 0, XSelectInput(display, m->bars[j]->window, ExposureMask);
TITLE, TITLE_BLUR, BORDER_BLUR, NULL, NULL);
XSelectInput(display, m->bars[j]->window, ExposureMask);
m->spots[j].y += m->bars[j]->h; m->spots[j].y += m->bars[j]->h;
m->spots[j].h -= m->bars[j]->h; m->spots[j].h -= m->bars[j]->h;
spot_update_bar(j, i); spot_update_bar(j, i);
}
} }
// setup existing managable windows // setup existing managable windows

53
spot.c
View File

@@ -24,39 +24,34 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#define SPOT_BUFF 1024
void spot_update_bar(int spot, int mon) void spot_update_bar(int spot, int mon)
{ {
int i, n = 0; client *o, *c = NULL; int i, n = 0, len = 0; client *o, *c = NULL;
char *title = alloca(SPOT_BUFF); *title = 0;
monitor *m = &monitors[mon]; monitor *m = &monitors[mon];
char *title = calloc(1024, sizeof(char));
int len = 0, lim = 1024;
for_windows(i, o) if (o->manage && o->spot == spot && o->monitor == mon) for_windows(i, o) if (o->manage && o->spot == spot && o->monitor == mon)
{ {
if (!c) c = o; if (!c) c = o;
char *name = NULL; char *name = NULL, *tmp = NULL;
if (!(name = window_get_text_prop(o->window, atoms[_NET_WM_NAME]))) if (!(name = window_get_text_prop(o->window, atoms[_NET_WM_NAME])))
{
char *tmp;
if (XFetchName(display, o->window, &tmp)) if (XFetchName(display, o->window, &tmp))
{
name = strdup(tmp); name = strdup(tmp);
XFree(tmp);
}
}
if (name) if (name)
{ {
if (TITLE_ELLIPSIS && strlen(name) > TITLE_ELLIPSIS) if (TITLE_ELLIPSIS > 0 && strlen(name) > TITLE_ELLIPSIS)
{ {
name = realloc(name, strlen(name)+4); name = realloc(name, strlen(name)+4);
strcpy(name+TITLE_ELLIPSIS, "..."); strcpy(name+TITLE_ELLIPSIS, "...");
} }
len += snprintf(title+len, MAX(0, lim-len), " [%d] %s ", n++, name); len += snprintf(title+len, MAX(0, SPOT_BUFF-len), " [%d] %s ", n++, name);
free(name); free(name);
} }
if (tmp) XFree(tmp);
} }
if (c && !c->full && title && m->bars[spot]) if (c && !c->full && *title && m->bars[spot])
{ {
int focus = c->window == current || (spot == current_spot && mon == current_mon); int focus = c->window == current || (spot == current_spot && mon == current_mon);
char *color = focus && c->window == current ? TITLE_FOCUS : TITLE_BLUR; char *color = focus && c->window == current ? TITLE_FOCUS : TITLE_BLUR;
@@ -69,31 +64,41 @@ void spot_update_bar(int spot, int mon)
else else
if (m->bars[spot]) if (m->bars[spot])
textbox_hide(m->bars[spot]); textbox_hide(m->bars[spot]);
free(title);
} }
void update_bars() void update_bars()
{ {
int i, j; monitor *m; int i, j; monitor *m;
for_monitors(i, m) for_spots(j) for_monitors(i, m) for_spots(j) spot_update_bar(j, i);
spot_update_bar(j, i);
} }
Window spot_focus_top_window(int spot, int mon, Window except) Window spot_focus_top_window(int spot, int mon, Window except)
{ {
int i; client *c; int i; client *c;
for_windows(i, c) for_windows(i, c) if (c->window != except && c->manage && c->spot == spot && c->monitor == mon)
{ {
if (c->window != except && c->manage && c->spot == spot && c->monitor == mon) client_raise_family(c);
{ client_set_focus(c);
client_raise_family(c); return c->window;
client_set_focus(c);
return c->window;
}
} }
return None; return None;
} }
Window spot_try_focus_top_window(int spot, int mon, Window except)
{
Window w = spot_focus_top_window(spot, mon, except);
if (w == None)
{
current = None;
current_mon = mon;
current_spot = spot;
update_bars();
XSetInputFocus(display, PointerRoot, RevertToPointerRoot, CurrentTime);
}
return w;
}
int spot_choose_by_direction(int spot, int mon, int dir) int spot_choose_by_direction(int spot, int mon, int dir)
{ {
monitor *m = &monitors[mon]; monitor *m = &monitors[mon];

View File

@@ -34,8 +34,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
typedef struct { typedef struct {
unsigned long flags; unsigned long flags;
Window window, parent; Window window, parent;
short x, y, w, h; short x, y, w, h, cursor;
short cursor;
XftFont *font; XftFont *font;
XftColor color_fg, color_bg; XftColor color_fg, color_bg;
char *text, *prompt; char *text, *prompt;
@@ -180,7 +179,6 @@ void textbox_draw(textbox *tb)
int text_len = strlen(text); int text_len = strlen(text);
int length = text_len; int length = text_len;
int line_height = tb->font->ascent + tb->font->descent; int line_height = tb->font->ascent + tb->font->descent;
int line_width = 0;
int cursor_x = 0; int cursor_x = 0;
int cursor_offset = 0; int cursor_offset = 0;
@@ -208,7 +206,7 @@ void textbox_draw(textbox *tb)
// calc full input text width // calc full input text width
XftTextExtents8(display, tb->font, (unsigned char*)line, length, &extents); XftTextExtents8(display, tb->font, (unsigned char*)line, length, &extents);
line_width = extents.width; int line_width = extents.width;
int x = 0, y = tb->font->ascent; int x = 0, y = tb->font->ascent;
if (tb->flags & TB_RIGHT) x = tb->w - line_width; if (tb->flags & TB_RIGHT) x = tb->w - line_width;
@@ -315,60 +313,29 @@ void textbox_cursor_bkspc(textbox *tb)
// -1 = handled and return pressed (finished) // -1 = handled and return pressed (finished)
int textbox_keypress(textbox *tb, XEvent *ev) int textbox_keypress(textbox *tb, XEvent *ev)
{ {
KeySym key; Status stat;
char pad[32]; int len;
if (!(tb->flags & TB_EDITABLE)) return 0; if (!(tb->flags & TB_EDITABLE)) return 0;
len = XmbLookupString(tb->xic, &ev->xkey, pad, sizeof(pad), &key, &stat); KeySym key; Status stat; char pad[32];
int len = XmbLookupString(tb->xic, &ev->xkey, pad, sizeof(pad), &key, &stat);
pad[len] = 0; pad[len] = 0;
if (key == XK_Left) switch (key)
{ {
textbox_cursor_dec(tb); case XK_Left : textbox_cursor_dec(tb); return 1;
return 1; case XK_Right : textbox_cursor_inc(tb); return 1;
} case XK_Home : textbox_cursor_home(tb); return 1;
else case XK_End : textbox_cursor_end(tb); return 1;
if (key == XK_Right) case XK_Delete : textbox_cursor_del(tb); return 1;
{ case XK_BackSpace : textbox_cursor_bkspc(tb); return 1;
textbox_cursor_inc(tb); case XK_Return : return -1;
return 1; default:
} if (!iscntrl(*pad))
else {
if (key == XK_Home) textbox_insert(tb, tb->cursor, pad);
{ textbox_cursor_inc(tb);
textbox_cursor_home(tb); return 1;
return 1; }
}
else
if (key == XK_End)
{
textbox_cursor_end(tb);
return 1;
}
else
if (key == XK_Delete)
{
textbox_cursor_del(tb);
return 1;
}
else
if (key == XK_BackSpace)
{
textbox_cursor_bkspc(tb);
return 1;
}
else
if (key == XK_Return)
{
return -1;
}
else
if (!iscntrl(*pad))
{
textbox_insert(tb, tb->cursor, pad);
textbox_cursor_inc(tb);
return 1;
} }
return 0; return 0;
} }

8
xoat.c
View File

@@ -77,7 +77,7 @@ typedef struct {
XWindowAttributes attr; XWindowAttributes attr;
Window transient, leader; Window transient, leader;
Atom type, states[ATOMLIST+1]; Atom type, states[ATOMLIST+1];
short monitor, visible, manage, input, urgent, full, above; short monitor, visible, manage, input, urgent, full, above, ours;
unsigned long spot; unsigned long spot;
char *class; char *class;
} client; } client;
@@ -191,10 +191,10 @@ void (*handlers[LASTEvent])(XEvent*) = {
int oops(Display *d, XErrorEvent *ee) int oops(Display *d, XErrorEvent *ee)
{ {
if (ee->error_code == BadWindow if (ee->error_code == BadWindow
|| (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch) || (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch)
|| (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch) || (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch)
|| (ee->request_code == X_GrabButton && ee->error_code == BadAccess) || (ee->request_code == X_GrabButton && ee->error_code == BadAccess)
|| (ee->request_code == X_GrabKey && ee->error_code == BadAccess) || (ee->request_code == X_GrabKey && ee->error_code == BadAccess)
) return 0; ) return 0;
fprintf(stderr, "error: request code=%d, error code=%d\n", ee->request_code, ee->error_code); fprintf(stderr, "error: request code=%d, error code=%d\n", ee->request_code, ee->error_code);
return xerror(display, ee); return xerror(display, ee);