Style cleanup
Signed-off-by: Christoph Lohmann <20h@r-36.net>
This commit is contained in:
parent
46887ac550
commit
735bed5824
|
@ -24,14 +24,16 @@ static Bool npisrelative = False;
|
|||
|
||||
#define SETPROP(p) { \
|
||||
.v = (char *[]){ "/bin/sh", "-c", \
|
||||
"prop=\"`xwininfo -children -id $1 | grep '^ 0x' | sed -e's@^ *\\(0x[0-9a-f]*\\) \"\\([^\"]*\\)\".*@\\1 \\2@' | xargs -0 printf %b | dmenu -l 10`\" &&" \
|
||||
"prop=\"`xwininfo -children -id $1 | grep '^ 0x' |" \
|
||||
"sed -e's@^ *\\(0x[0-9a-f]*\\) \"\\([^\"]*\\)\".*@\\1 \\2@' |" \
|
||||
"xargs -0 printf %b | dmenu -l 10`\" &&" \
|
||||
"xprop -id $1 -f $0 8s -set $0 \"$prop\"", \
|
||||
p, winid, NULL \
|
||||
} \
|
||||
}
|
||||
|
||||
#define MODKEY ControlMask
|
||||
static Key keys[] = { \
|
||||
static Key keys[] = {
|
||||
/* modifier key function argument */
|
||||
{ MODKEY|ShiftMask, XK_Return, focusonce, { 0 } },
|
||||
{ MODKEY|ShiftMask, XK_Return, spawn, { 0 } },
|
||||
|
@ -56,9 +58,8 @@ static Key keys[] = { \
|
|||
|
||||
{ MODKEY, XK_q, killclient, { 0 } },
|
||||
|
||||
{ MODKEY, XK_u, focusurgent, { .v = NULL } },
|
||||
{ MODKEY, XK_u, focusurgent, { 0 } },
|
||||
{ MODKEY|ShiftMask, XK_u, toggle, { .v = (void*) &urgentswitch } },
|
||||
|
||||
{ 0, XK_F11, fullscreen, { 0 } },
|
||||
};
|
||||
|
||||
|
|
421
tabbed.c
421
tabbed.c
|
@ -4,12 +4,12 @@
|
|||
|
||||
#include <sys/wait.h>
|
||||
#include <locale.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xproto.h>
|
||||
|
@ -78,7 +78,7 @@ typedef struct {
|
|||
} font;
|
||||
} DC; /* draw context */
|
||||
|
||||
typedef struct Client {
|
||||
typedef struct {
|
||||
char name[256];
|
||||
Window win;
|
||||
int tabx;
|
||||
|
@ -93,7 +93,6 @@ static void clientmessage(const XEvent *e);
|
|||
static void configurenotify(const XEvent *e);
|
||||
static void configurerequest(const XEvent *e);
|
||||
static void createnotify(const XEvent *e);
|
||||
static void unmapnotify(const XEvent *e);
|
||||
static void destroynotify(const XEvent *e);
|
||||
static void die(const char *errstr, ...);
|
||||
static void drawbar(void);
|
||||
|
@ -104,7 +103,7 @@ static void expose(const XEvent *e);
|
|||
static void focus(int c);
|
||||
static void focusin(const XEvent *e);
|
||||
static void focusonce(const Arg *arg);
|
||||
static void focusurgent(const Arg *);
|
||||
static void focusurgent(const Arg *arg);
|
||||
static void fullscreen(const Arg *arg);
|
||||
static char *getatom(int a);
|
||||
static int getclient(Window w);
|
||||
|
@ -124,13 +123,14 @@ static void resize(int c, int w, int h);
|
|||
static void rotate(const Arg *arg);
|
||||
static void run(void);
|
||||
static void sendxembed(int c, long msg, long detail, long d1, long d2);
|
||||
static void setup(void);
|
||||
static void setcmd(int argc, char *argv[], int);
|
||||
static void setup(void);
|
||||
static void sigchld(int unused);
|
||||
static void spawn(const Arg *arg);
|
||||
static int textnw(const char *text, unsigned int len);
|
||||
static void toggle(const Arg *arg);
|
||||
static void unmanage(int c);
|
||||
static void unmapnotify(const XEvent *e);
|
||||
static void updatenumlockmask(void);
|
||||
static void updatetitle(int c);
|
||||
static int xerror(Display *dpy, XErrorEvent *ee);
|
||||
|
@ -153,21 +153,21 @@ static void (*handler[LASTEvent]) (const XEvent *) = {
|
|||
[PropertyNotify] = propertynotify,
|
||||
};
|
||||
static int bh, wx, wy, ww, wh;
|
||||
static unsigned int numlockmask = 0;
|
||||
static unsigned int numlockmask;
|
||||
static Bool running = True, nextfocus, doinitspawn = True,
|
||||
fillagain = False, closelastclient = False;
|
||||
static Display *dpy;
|
||||
static DC dc;
|
||||
static Atom wmatom[WMLast];
|
||||
static Window root, win;
|
||||
static Client **clients = NULL;
|
||||
static int nclients = 0, sel = -1, lastsel = -1;
|
||||
static Client **clients;
|
||||
static int nclients, sel = -1, lastsel = -1;
|
||||
static int (*xerrorxlib)(Display *, XErrorEvent *);
|
||||
static int cmd_append_pos = 0;
|
||||
static int cmd_append_pos;
|
||||
static char winid[64];
|
||||
static char **cmd = NULL;
|
||||
static char **cmd;
|
||||
static char *wmname = "tabbed";
|
||||
static const char *geometry = NULL;
|
||||
static const char *geometry;
|
||||
|
||||
char *argv0;
|
||||
|
||||
|
@ -175,10 +175,10 @@ char *argv0;
|
|||
#include "config.h"
|
||||
|
||||
void
|
||||
buttonpress(const XEvent *e) {
|
||||
buttonpress(const XEvent *e)
|
||||
{
|
||||
const XButtonPressedEvent *ev = &e->xbutton;
|
||||
int i;
|
||||
int fc;
|
||||
int i, fc;
|
||||
Arg arg;
|
||||
|
||||
if (ev->y < 0 || ev->y > bh)
|
||||
|
@ -197,7 +197,7 @@ buttonpress(const XEvent *e) {
|
|||
focus(i);
|
||||
killclient(NULL);
|
||||
break;
|
||||
case Button4:
|
||||
case Button4: /* FALLTHROUGH */
|
||||
case Button5:
|
||||
arg.i = ev->button == Button4 ? -1 : 1;
|
||||
rotate(&arg);
|
||||
|
@ -209,7 +209,8 @@ buttonpress(const XEvent *e) {
|
|||
}
|
||||
|
||||
void
|
||||
cleanup(void) {
|
||||
cleanup(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nclients; i++) {
|
||||
|
@ -222,11 +223,10 @@ cleanup(void) {
|
|||
free(clients);
|
||||
clients = NULL;
|
||||
|
||||
if(dc.font.set) {
|
||||
if (dc.font.set)
|
||||
XFreeFontSet(dpy, dc.font.set);
|
||||
} else {
|
||||
else
|
||||
XFreeFont(dpy, dc.font.xfont);
|
||||
}
|
||||
|
||||
XFreePixmap(dpy, dc.drawable);
|
||||
XFreeGC(dpy, dc.gc);
|
||||
|
@ -236,17 +236,18 @@ cleanup(void) {
|
|||
}
|
||||
|
||||
void
|
||||
clientmessage(const XEvent *e) {
|
||||
clientmessage(const XEvent *e)
|
||||
{
|
||||
const XClientMessageEvent *ev = &e->xclient;
|
||||
|
||||
if(ev->message_type == wmatom[WMProtocols]
|
||||
&& ev->data.l[0] == wmatom[WMDelete]) {
|
||||
if (ev->message_type == wmatom[WMProtocols] &&
|
||||
ev->data.l[0] == wmatom[WMDelete])
|
||||
running = False;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
configurenotify(const XEvent *e) {
|
||||
configurenotify(const XEvent *e)
|
||||
{
|
||||
const XConfigureEvent *ev = &e->xconfigure;
|
||||
|
||||
if (ev->window == win && (ev->width != ww || ev->height != wh)) {
|
||||
|
@ -262,7 +263,8 @@ configurenotify(const XEvent *e) {
|
|||
}
|
||||
|
||||
void
|
||||
configurerequest(const XEvent *e) {
|
||||
configurerequest(const XEvent *e)
|
||||
{
|
||||
const XConfigureRequestEvent *ev = &e->xconfigurerequest;
|
||||
XWindowChanges wc;
|
||||
int c;
|
||||
|
@ -280,7 +282,8 @@ configurerequest(const XEvent *e) {
|
|||
}
|
||||
|
||||
void
|
||||
createnotify(const XEvent *e) {
|
||||
createnotify(const XEvent *e)
|
||||
{
|
||||
const XCreateWindowEvent *ev = &e->xcreatewindow;
|
||||
|
||||
if (ev->window != win && getclient(ev->window) < 0)
|
||||
|
@ -288,16 +291,8 @@ createnotify(const XEvent *e) {
|
|||
}
|
||||
|
||||
void
|
||||
unmapnotify(const XEvent *e) {
|
||||
const XUnmapEvent *ev = &e->xunmap;
|
||||
int c;
|
||||
|
||||
if((c = getclient(ev->window)) > -1)
|
||||
unmanage(c);
|
||||
}
|
||||
|
||||
void
|
||||
destroynotify(const XEvent *e) {
|
||||
destroynotify(const XEvent *e)
|
||||
{
|
||||
const XDestroyWindowEvent *ev = &e->xdestroywindow;
|
||||
int c;
|
||||
|
||||
|
@ -306,7 +301,8 @@ destroynotify(const XEvent *e) {
|
|||
}
|
||||
|
||||
void
|
||||
die(const char *errstr, ...) {
|
||||
die(const char *errstr, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, errstr);
|
||||
|
@ -316,7 +312,8 @@ die(const char *errstr, ...) {
|
|||
}
|
||||
|
||||
void
|
||||
drawbar(void) {
|
||||
drawbar(void)
|
||||
{
|
||||
unsigned long *col;
|
||||
int c, cc, fc, width;
|
||||
char *name = NULL;
|
||||
|
@ -370,7 +367,8 @@ drawbar(void) {
|
|||
}
|
||||
|
||||
void
|
||||
drawtext(const char *text, unsigned long col[ColLast]) {
|
||||
drawtext(const char *text, unsigned long col[ColLast])
|
||||
{
|
||||
int i, x, y, h, len, olen;
|
||||
char buf[256];
|
||||
XRectangle r = { dc.x, dc.y, dc.w, dc.h };
|
||||
|
@ -388,25 +386,25 @@ drawtext(const char *text, unsigned long col[ColLast]) {
|
|||
/* shorten text if necessary */
|
||||
for (len = MIN(olen, sizeof(buf));
|
||||
len && textnw(text, len) > dc.w - h; len--);
|
||||
|
||||
if (!len)
|
||||
return;
|
||||
|
||||
memcpy(buf, text, len);
|
||||
if(len < olen) {
|
||||
if (len < olen)
|
||||
for(i = len; i && i > len - 3; buf[--i] = '.');
|
||||
}
|
||||
|
||||
XSetForeground(dpy, dc.gc, col[ColFG]);
|
||||
if(dc.font.set) {
|
||||
if (dc.font.set)
|
||||
XmbDrawString(dpy, dc.drawable, dc.font.set,
|
||||
dc.gc, x, y, buf, len);
|
||||
} else {
|
||||
else
|
||||
XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
|
||||
}
|
||||
}
|
||||
|
||||
void *
|
||||
ecalloc(size_t n, size_t size) {
|
||||
ecalloc(size_t n, size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
if (!(p = calloc(n, size)))
|
||||
|
@ -415,7 +413,8 @@ ecalloc(size_t n, size_t size) {
|
|||
}
|
||||
|
||||
void *
|
||||
erealloc(void *o, size_t size) {
|
||||
erealloc(void *o, size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
if (!(p = realloc(o, size)))
|
||||
|
@ -424,7 +423,8 @@ erealloc(void *o, size_t size) {
|
|||
}
|
||||
|
||||
void
|
||||
expose(const XEvent *e) {
|
||||
expose(const XEvent *e)
|
||||
{
|
||||
const XExposeEvent *ev = &e->xexpose;
|
||||
|
||||
if (ev->count == 0 && win == ev->window)
|
||||
|
@ -432,7 +432,8 @@ expose(const XEvent *e) {
|
|||
}
|
||||
|
||||
void
|
||||
focus(int c) {
|
||||
focus(int c)
|
||||
{
|
||||
char buf[BUFSIZ] = "tabbed-"VERSION" ::";
|
||||
size_t i, n;
|
||||
XWMHints* wmh;
|
||||
|
@ -476,7 +477,8 @@ focus(int c) {
|
|||
}
|
||||
|
||||
void
|
||||
focusin(const XEvent *e) {
|
||||
focusin(const XEvent *e)
|
||||
{
|
||||
const XFocusChangeEvent *ev = &e->xfocus;
|
||||
int dummy;
|
||||
Window focused;
|
||||
|
@ -489,13 +491,16 @@ focusin(const XEvent *e) {
|
|||
}
|
||||
|
||||
void
|
||||
focusonce(const Arg *arg) {
|
||||
focusonce(const Arg *arg)
|
||||
{
|
||||
nextfocus = True;
|
||||
}
|
||||
|
||||
void
|
||||
focusurgent(const Arg *args) {
|
||||
focusurgent(const Arg *arg)
|
||||
{
|
||||
int c;
|
||||
|
||||
for (c = (sel + 1) % nclients; c != sel; c = (c + 1) % nclients) {
|
||||
if (clients[c]->urgent) {
|
||||
focus(c);
|
||||
|
@ -505,7 +510,8 @@ focusurgent(const Arg *args) {
|
|||
}
|
||||
|
||||
void
|
||||
fullscreen(const Arg *arg) {
|
||||
fullscreen(const Arg *arg)
|
||||
{
|
||||
XEvent e;
|
||||
|
||||
e.type = ClientMessage;
|
||||
|
@ -519,7 +525,8 @@ fullscreen(const Arg *arg) {
|
|||
}
|
||||
|
||||
char *
|
||||
getatom(int a) {
|
||||
getatom(int a)
|
||||
{
|
||||
static char buf[BUFSIZ];
|
||||
Atom adummy;
|
||||
int idummy;
|
||||
|
@ -528,18 +535,18 @@ getatom(int a) {
|
|||
|
||||
XGetWindowProperty(dpy, win, wmatom[a], 0L, BUFSIZ, False, XA_STRING,
|
||||
&adummy, &idummy, &ldummy, &ldummy, &p);
|
||||
if(p) {
|
||||
if (p)
|
||||
strncpy(buf, (char *)p, LENGTH(buf)-1);
|
||||
} else {
|
||||
else
|
||||
buf[0] = '\0';
|
||||
}
|
||||
XFree(p);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
int
|
||||
getclient(Window w) {
|
||||
getclient(Window w)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nclients; i++) {
|
||||
|
@ -551,7 +558,8 @@ getclient(Window w) {
|
|||
}
|
||||
|
||||
unsigned long
|
||||
getcolor(const char *colstr) {
|
||||
getcolor(const char *colstr)
|
||||
{
|
||||
Colormap cmap = DefaultColormap(dpy, screen);
|
||||
XColor color;
|
||||
|
||||
|
@ -562,7 +570,8 @@ getcolor(const char *colstr) {
|
|||
}
|
||||
|
||||
int
|
||||
getfirsttab(void) {
|
||||
getfirsttab(void)
|
||||
{
|
||||
int cc, ret;
|
||||
|
||||
if (sel < 0)
|
||||
|
@ -573,11 +582,14 @@ getfirsttab(void) {
|
|||
cc = (ww - TEXTW(before) - TEXTW(after)) / tabwidth;
|
||||
|
||||
ret = sel - cc / 2 + (cc + 1) % 2;
|
||||
return ret < 0 ? 0 : (ret + cc > nclients ? MAX(0, nclients - cc) : ret);
|
||||
return ret < 0 ? 0 :
|
||||
ret + cc > nclients ? MAX(0, nclients - cc) :
|
||||
ret;
|
||||
}
|
||||
|
||||
Bool
|
||||
gettextprop(Window w, Atom atom, char *text, unsigned int size) {
|
||||
gettextprop(Window w, Atom atom, char *text, unsigned int size)
|
||||
{
|
||||
char **list = NULL;
|
||||
int n;
|
||||
XTextProperty name;
|
||||
|
@ -592,13 +604,11 @@ gettextprop(Window w, Atom atom, char *text, unsigned int size) {
|
|||
|
||||
if (name.encoding == XA_STRING) {
|
||||
strncpy(text, (char *)name.value, size - 1);
|
||||
} else {
|
||||
if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
|
||||
} else if (XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
|
||||
&& n > 0 && *list) {
|
||||
strncpy(text, *list, size - 1);
|
||||
XFreeStringList(list);
|
||||
}
|
||||
}
|
||||
text[size - 1] = '\0';
|
||||
XFree(name.value);
|
||||
|
||||
|
@ -606,10 +616,11 @@ gettextprop(Window w, Atom atom, char *text, unsigned int size) {
|
|||
}
|
||||
|
||||
void
|
||||
initfont(const char *fontstr) {
|
||||
initfont(const char *fontstr)
|
||||
{
|
||||
char *def, **missing, **font_names;
|
||||
int i, n;
|
||||
XFontStruct **xfonts;
|
||||
int i, n;
|
||||
|
||||
missing = NULL;
|
||||
if (dc.font.set)
|
||||
|
@ -625,7 +636,8 @@ initfont(const char *fontstr) {
|
|||
if (dc.font.set) {
|
||||
dc.font.ascent = dc.font.descent = 0;
|
||||
n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
|
||||
for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
|
||||
for (i = 0, dc.font.ascent = 0, dc.font.descent = 0;
|
||||
i < n; i++) {
|
||||
dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent);
|
||||
dc.font.descent = MAX(dc.font.descent,(*xfonts)->descent);
|
||||
xfonts++;
|
||||
|
@ -634,10 +646,9 @@ initfont(const char *fontstr) {
|
|||
if (dc.font.xfont)
|
||||
XFreeFont(dpy, dc.font.xfont);
|
||||
dc.font.xfont = NULL;
|
||||
if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr))
|
||||
&& !(dc.font.xfont = XLoadQueryFont(dpy, "fixed"))) {
|
||||
if (!(dc.font.xfont = XLoadQueryFont(dpy, fontstr)) &&
|
||||
!(dc.font.xfont = XLoadQueryFont(dpy, "fixed")))
|
||||
die("tabbed: cannot load font: '%s'\n", fontstr);
|
||||
}
|
||||
|
||||
dc.font.ascent = dc.font.xfont->ascent;
|
||||
dc.font.descent = dc.font.xfont->descent;
|
||||
|
@ -646,7 +657,8 @@ initfont(const char *fontstr) {
|
|||
}
|
||||
|
||||
Bool
|
||||
isprotodel(int c) {
|
||||
isprotodel(int c)
|
||||
{
|
||||
int i, n;
|
||||
Atom *protocols;
|
||||
Bool ret = False;
|
||||
|
@ -663,23 +675,24 @@ isprotodel(int c) {
|
|||
}
|
||||
|
||||
void
|
||||
keypress(const XEvent *e) {
|
||||
keypress(const XEvent *e)
|
||||
{
|
||||
const XKeyEvent *ev = &e->xkey;
|
||||
unsigned int i;
|
||||
KeySym keysym;
|
||||
|
||||
keysym = XkbKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0, 0);
|
||||
for (i = 0; i < LENGTH(keys); i++) {
|
||||
if(keysym == keys[i].keysym
|
||||
&& CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)
|
||||
&& keys[i].func) {
|
||||
if (keysym == keys[i].keysym &&
|
||||
CLEANMASK(keys[i].mod) == CLEANMASK(ev->state) &&
|
||||
keys[i].func)
|
||||
keys[i].func(&(keys[i].arg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
killclient(const Arg *arg) {
|
||||
killclient(const Arg *arg)
|
||||
{
|
||||
XEvent ev;
|
||||
|
||||
if (sel < 0)
|
||||
|
@ -700,7 +713,8 @@ killclient(const Arg *arg) {
|
|||
}
|
||||
|
||||
void
|
||||
manage(Window w) {
|
||||
manage(Window w)
|
||||
{
|
||||
updatenumlockmask();
|
||||
{
|
||||
int i, j, nextpos;
|
||||
|
@ -712,17 +726,16 @@ manage(Window w) {
|
|||
|
||||
XWithdrawWindow(dpy, w, 0);
|
||||
XReparentWindow(dpy, w, win, 0, bh);
|
||||
XSelectInput(dpy, w, PropertyChangeMask
|
||||
|StructureNotifyMask|EnterWindowMask);
|
||||
XSelectInput(dpy, w, PropertyChangeMask |
|
||||
StructureNotifyMask | EnterWindowMask);
|
||||
XSync(dpy, False);
|
||||
|
||||
for (i = 0; i < LENGTH(keys); i++) {
|
||||
if ((code = XKeysymToKeycode(dpy, keys[i].keysym))) {
|
||||
for (j = 0; j < LENGTH(modifiers); j++) {
|
||||
XGrabKey(dpy, code, keys[i].mod
|
||||
| modifiers[j], w,
|
||||
True, GrabModeAsync,
|
||||
GrabModeAsync);
|
||||
XGrabKey(dpy, code, keys[i].mod |
|
||||
modifiers[j], w, True,
|
||||
GrabModeAsync, GrabModeAsync);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -736,22 +749,20 @@ manage(Window w) {
|
|||
if(npisrelative) {
|
||||
nextpos = sel + newposition;
|
||||
} else {
|
||||
if(newposition < 0) {
|
||||
if (newposition < 0)
|
||||
nextpos = nclients - newposition;
|
||||
} else {
|
||||
else
|
||||
nextpos = newposition;
|
||||
}
|
||||
}
|
||||
if (nextpos >= nclients)
|
||||
nextpos = nclients - 1;
|
||||
if (nextpos < 0)
|
||||
nextpos = 0;
|
||||
|
||||
if(nclients > 1 && nextpos < nclients - 1) {
|
||||
if (nclients > 1 && nextpos < nclients - 1)
|
||||
memmove(&clients[nextpos + 1], &clients[nextpos],
|
||||
sizeof(Client *) *
|
||||
(nclients - nextpos - 1));
|
||||
}
|
||||
sizeof(Client *) * (nclients - nextpos - 1));
|
||||
|
||||
clients[nextpos] = c;
|
||||
updatetitle(nextpos);
|
||||
|
||||
|
@ -774,13 +785,16 @@ manage(Window w) {
|
|||
/* Adjust sel before focus does set it to lastsel. */
|
||||
if (sel >= nextpos)
|
||||
sel++;
|
||||
focus((nextfocus)? nextpos : ((sel < 0)? 0 : sel));
|
||||
focus(nextfocus ? nextpos :
|
||||
sel < 0 ? 0 :
|
||||
sel);
|
||||
nextfocus = foreground;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
maprequest(const XEvent *e) {
|
||||
maprequest(const XEvent *e)
|
||||
{
|
||||
const XMapRequestEvent *ev = &e->xmaprequest;
|
||||
|
||||
if (getclient(ev->window) < 0)
|
||||
|
@ -788,13 +802,15 @@ maprequest(const XEvent *e) {
|
|||
}
|
||||
|
||||
void
|
||||
move(const Arg *arg) {
|
||||
move(const Arg *arg)
|
||||
{
|
||||
if (arg->i >= 0 && arg->i < nclients)
|
||||
focus(arg->i);
|
||||
}
|
||||
|
||||
void
|
||||
movetab(const Arg *arg) {
|
||||
movetab(const Arg *arg)
|
||||
{
|
||||
int c;
|
||||
Client *new;
|
||||
|
||||
|
@ -802,14 +818,16 @@ movetab(const Arg *arg) {
|
|||
if (c < 0)
|
||||
c += nclients;
|
||||
|
||||
if(sel < 0 || (c == sel))
|
||||
if (sel < 0 || c == sel)
|
||||
return;
|
||||
|
||||
new = clients[sel];
|
||||
if (sel < c)
|
||||
memmove(&clients[sel], &clients[sel+1], sizeof(Client *) * (c - sel));
|
||||
memmove(&clients[sel], &clients[sel+1],
|
||||
sizeof(Client *) * (c - sel));
|
||||
else
|
||||
memmove(&clients[c+1], &clients[c], sizeof(Client *) * (sel - c));
|
||||
memmove(&clients[c+1], &clients[c],
|
||||
sizeof(Client *) * (sel - c));
|
||||
clients[c] = new;
|
||||
sel = c;
|
||||
|
||||
|
@ -817,7 +835,8 @@ movetab(const Arg *arg) {
|
|||
}
|
||||
|
||||
void
|
||||
propertynotify(const XEvent *e) {
|
||||
propertynotify(const XEvent *e)
|
||||
{
|
||||
const XPropertyEvent *ev = &e->xproperty;
|
||||
XWMHints *wmh;
|
||||
int c;
|
||||
|
@ -834,38 +853,44 @@ propertynotify(const XEvent *e) {
|
|||
arg.v = cmd;
|
||||
spawn(&arg);
|
||||
}
|
||||
} else if(ev->state == PropertyNewValue && ev->atom == XA_WM_HINTS
|
||||
&& (c = getclient(ev->window)) > -1
|
||||
&& (wmh = XGetWMHints(dpy, clients[c]->win))) {
|
||||
} else if (ev->state == PropertyNewValue && ev->atom == XA_WM_HINTS &&
|
||||
(c = getclient(ev->window)) > -1 &&
|
||||
(wmh = XGetWMHints(dpy, clients[c]->win))) {
|
||||
if (wmh->flags & XUrgencyHint) {
|
||||
XFree(wmh);
|
||||
wmh = XGetWMHints(dpy, win);
|
||||
if (c != sel) {
|
||||
if(urgentswitch && wmh && !(wmh->flags & XUrgencyHint)) {
|
||||
/* only switch, if tabbed was focused since last urgency hint
|
||||
* if WMHints could not be received, default to no switch */
|
||||
if (urgentswitch && wmh &&
|
||||
!(wmh->flags & XUrgencyHint)) {
|
||||
/* only switch, if tabbed was focused
|
||||
* since last urgency hint if WMHints
|
||||
* could not be received,
|
||||
* default to no switch */
|
||||
focus(c);
|
||||
} else {
|
||||
/* if no switch should be performed, mark tab as urgent */
|
||||
/* if no switch should be performed,
|
||||
* mark tab as urgent */
|
||||
clients[c]->urgent = True;
|
||||
drawbar();
|
||||
}
|
||||
}
|
||||
if (wmh && !(wmh->flags & XUrgencyHint)) {
|
||||
/* update tabbed urgency hint if not set already */
|
||||
/* update tabbed urgency hint
|
||||
* if not set already */
|
||||
wmh->flags |= XUrgencyHint;
|
||||
XSetWMHints(dpy, win, wmh);
|
||||
}
|
||||
}
|
||||
XFree(wmh);
|
||||
} else if(ev->state != PropertyDelete && ev->atom == XA_WM_NAME
|
||||
&& (c = getclient(ev->window)) > -1) {
|
||||
} else if (ev->state != PropertyDelete && ev->atom == XA_WM_NAME &&
|
||||
(c = getclient(ev->window)) > -1) {
|
||||
updatetitle(c);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
resize(int c, int w, int h) {
|
||||
resize(int c, int w, int h)
|
||||
{
|
||||
XConfigureEvent ce;
|
||||
XWindowChanges wc;
|
||||
|
||||
|
@ -887,7 +912,8 @@ resize(int c, int w, int h) {
|
|||
}
|
||||
|
||||
void
|
||||
rotate(const Arg *arg) {
|
||||
rotate(const Arg *arg)
|
||||
{
|
||||
int nsel = -1;
|
||||
|
||||
if (sel < 0)
|
||||
|
@ -908,7 +934,8 @@ rotate(const Arg *arg) {
|
|||
}
|
||||
|
||||
void
|
||||
run(void) {
|
||||
run(void)
|
||||
{
|
||||
XEvent ev;
|
||||
|
||||
/* main event loop */
|
||||
|
@ -925,7 +952,8 @@ run(void) {
|
|||
}
|
||||
|
||||
void
|
||||
sendxembed(int c, long msg, long detail, long d1, long d2) {
|
||||
sendxembed(int c, long msg, long detail, long d1, long d2)
|
||||
{
|
||||
XEvent e = { 0 };
|
||||
|
||||
e.xclient.window = clients[c]->win;
|
||||
|
@ -941,21 +969,23 @@ sendxembed(int c, long msg, long detail, long d1, long d2) {
|
|||
}
|
||||
|
||||
void
|
||||
setcmd(int argc, char *argv[], int replace) {
|
||||
setcmd(int argc, char *argv[], int replace)
|
||||
{
|
||||
int i;
|
||||
|
||||
cmd = ecalloc(argc + 3, sizeof *cmd);
|
||||
cmd = ecalloc(argc + 3, sizeof(*cmd));
|
||||
if (argc == 0)
|
||||
return;
|
||||
for (i = 0; i < argc; i++)
|
||||
cmd[i] = argv[i];
|
||||
cmd[(replace > 0)? replace : argc] = winid;
|
||||
cmd[replace > 0 ? replace : argc] = winid;
|
||||
cmd_append_pos = argc + !replace;
|
||||
cmd[cmd_append_pos] = cmd[cmd_append_pos + 1] = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
setup(void) {
|
||||
setup(void)
|
||||
{
|
||||
int bitm, tx, ty, tw, th, dh, dw, isfixed;
|
||||
XWMHints *wmh;
|
||||
XClassHint class_hint;
|
||||
|
@ -971,13 +1001,14 @@ setup(void) {
|
|||
bh = dc.h = dc.font.height + 2;
|
||||
|
||||
/* init atoms */
|
||||
wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
|
||||
wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
|
||||
wmatom[XEmbed] = XInternAtom(dpy, "_XEMBED", False);
|
||||
wmatom[WMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN",
|
||||
False);
|
||||
wmatom[WMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
|
||||
wmatom[WMState] = XInternAtom(dpy, "_NET_WM_STATE", False);
|
||||
wmatom[WMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False);
|
||||
wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
|
||||
wmatom[WMSelectTab] = XInternAtom(dpy, "_TABBED_SELECT_TAB", False);
|
||||
wmatom[WMState] = XInternAtom(dpy, "_NET_WM_STATE", False);
|
||||
wmatom[XEmbed] = XInternAtom(dpy, "_XEMBED", False);
|
||||
|
||||
/* init appearance */
|
||||
wx = 0;
|
||||
|
@ -1029,8 +1060,9 @@ setup(void) {
|
|||
dc.norm[ColFG], dc.norm[ColBG]);
|
||||
XMapRaised(dpy, win);
|
||||
XSelectInput(dpy, win, SubstructureNotifyMask | FocusChangeMask |
|
||||
ButtonPressMask|ExposureMask|KeyPressMask|PropertyChangeMask|
|
||||
StructureNotifyMask|SubstructureRedirectMask);
|
||||
ButtonPressMask | ExposureMask | KeyPressMask |
|
||||
PropertyChangeMask | StructureNotifyMask |
|
||||
SubstructureRedirectMask);
|
||||
xerrorxlib = XSetErrorHandler(xerror);
|
||||
|
||||
class_hint.res_name = wmname;
|
||||
|
@ -1062,7 +1094,8 @@ setup(void) {
|
|||
}
|
||||
|
||||
void
|
||||
sigchld(int unused) {
|
||||
sigchld(int unused)
|
||||
{
|
||||
if (signal(SIGCHLD, sigchld) == SIG_ERR)
|
||||
die("tabbed: cannot install SIGCHLD handler");
|
||||
|
||||
|
@ -1070,7 +1103,8 @@ sigchld(int unused) {
|
|||
}
|
||||
|
||||
void
|
||||
spawn(const Arg *arg) {
|
||||
spawn(const Arg *arg)
|
||||
{
|
||||
if (fork() == 0) {
|
||||
if(dpy)
|
||||
close(ConnectionNumber(dpy));
|
||||
|
@ -1091,12 +1125,12 @@ spawn(const Arg *arg) {
|
|||
}
|
||||
|
||||
int
|
||||
textnw(const char *text, unsigned int len) {
|
||||
textnw(const char *text, unsigned int len)
|
||||
{
|
||||
XRectangle r;
|
||||
|
||||
if (dc.font.set) {
|
||||
XmbTextExtents(dc.font.set, text, len, NULL, &r);
|
||||
|
||||
return r.width;
|
||||
}
|
||||
|
||||
|
@ -1104,12 +1138,14 @@ textnw(const char *text, unsigned int len) {
|
|||
}
|
||||
|
||||
void
|
||||
toggle(const Arg *arg) {
|
||||
toggle(const Arg *arg)
|
||||
{
|
||||
*(Bool*) arg->v = !*(Bool*) arg->v;
|
||||
}
|
||||
|
||||
void
|
||||
unmanage(int c) {
|
||||
unmanage(int c)
|
||||
{
|
||||
if (c < 0 || c >= nclients) {
|
||||
drawbar();
|
||||
XSync(dpy, False);
|
||||
|
@ -1140,17 +1176,15 @@ unmanage(int c) {
|
|||
if (nclients <= 0) {
|
||||
lastsel = sel = -1;
|
||||
|
||||
if(closelastclient) {
|
||||
if (closelastclient)
|
||||
running = False;
|
||||
} else if(fillagain && running) {
|
||||
else if (fillagain && running)
|
||||
spawn(NULL);
|
||||
}
|
||||
} else {
|
||||
if(lastsel >= nclients) {
|
||||
if (lastsel >= nclients)
|
||||
lastsel = nclients - 1;
|
||||
} else if(lastsel > c) {
|
||||
else if (lastsel > c)
|
||||
lastsel--;
|
||||
}
|
||||
|
||||
if (c == sel && lastsel >= 0) {
|
||||
focus(lastsel);
|
||||
|
@ -1169,7 +1203,18 @@ unmanage(int c) {
|
|||
}
|
||||
|
||||
void
|
||||
updatenumlockmask(void) {
|
||||
unmapnotify(const XEvent *e)
|
||||
{
|
||||
const XUnmapEvent *ev = &e->xunmap;
|
||||
int c;
|
||||
|
||||
if ((c = getclient(ev->window)) > -1)
|
||||
unmanage(c);
|
||||
}
|
||||
|
||||
void
|
||||
updatenumlockmask(void)
|
||||
{
|
||||
unsigned int i, j;
|
||||
XModifierKeymap *modmap;
|
||||
|
||||
|
@ -1178,22 +1223,20 @@ updatenumlockmask(void) {
|
|||
for (i = 0; i < 8; i++) {
|
||||
for (j = 0; j < modmap->max_keypermod; j++) {
|
||||
if (modmap->modifiermap[i * modmap->max_keypermod + j]
|
||||
== XKeysymToKeycode(dpy,
|
||||
XK_Num_Lock)) {
|
||||
== XKeysymToKeycode(dpy, XK_Num_Lock))
|
||||
numlockmask = (1 << i);
|
||||
}
|
||||
}
|
||||
}
|
||||
XFreeModifiermap(modmap);
|
||||
}
|
||||
|
||||
void
|
||||
updatetitle(int c) {
|
||||
if(!gettextprop(clients[c]->win, wmatom[WMName],
|
||||
clients[c]->name, sizeof(clients[c]->name))) {
|
||||
gettextprop(clients[c]->win, XA_WM_NAME,
|
||||
clients[c]->name, sizeof(clients[c]->name));
|
||||
}
|
||||
updatetitle(int c)
|
||||
{
|
||||
if (!gettextprop(clients[c]->win, wmatom[WMName], clients[c]->name,
|
||||
sizeof(clients[c]->name)))
|
||||
gettextprop(clients[c]->win, XA_WM_NAME, clients[c]->name,
|
||||
sizeof(clients[c]->name));
|
||||
if (sel == c)
|
||||
xsettitle(win, clients[c]->name);
|
||||
drawbar();
|
||||
|
@ -1203,26 +1246,26 @@ updatetitle(int c) {
|
|||
* ignored (especially on UnmapNotify's). Other types of errors call Xlibs
|
||||
* default error handler, which may call exit. */
|
||||
int
|
||||
xerror(Display *dpy, XErrorEvent *ee) {
|
||||
xerror(Display *dpy, XErrorEvent *ee)
|
||||
{
|
||||
if (ee->error_code == BadWindow
|
||||
|| (ee->request_code == X_SetInputFocus
|
||||
&& ee->error_code == BadMatch)
|
||||
|| (ee->request_code == X_PolyText8
|
||||
&& ee->error_code == BadDrawable)
|
||||
|| (ee->request_code == X_PolyFillRectangle
|
||||
&& ee->error_code == BadDrawable)
|
||||
|| (ee->request_code == X_PolySegment
|
||||
&& ee->error_code == BadDrawable)
|
||||
|| (ee->request_code == X_ConfigureWindow
|
||||
&& ee->error_code == BadMatch)
|
||||
|| (ee->request_code == X_GrabButton
|
||||
&& ee->error_code == BadAccess)
|
||||
|| (ee->request_code == X_GrabKey
|
||||
&& ee->error_code == BadAccess)
|
||||
|| (ee->request_code == X_CopyArea
|
||||
&& ee->error_code == BadDrawable)) {
|
||||
|| (ee->request_code == X_SetInputFocus &&
|
||||
ee->error_code == BadMatch)
|
||||
|| (ee->request_code == X_PolyText8 &&
|
||||
ee->error_code == BadDrawable)
|
||||
|| (ee->request_code == X_PolyFillRectangle &&
|
||||
ee->error_code == BadDrawable)
|
||||
|| (ee->request_code == X_PolySegment &&
|
||||
ee->error_code == BadDrawable)
|
||||
|| (ee->request_code == X_ConfigureWindow &&
|
||||
ee->error_code == BadMatch)
|
||||
|| (ee->request_code == X_GrabButton &&
|
||||
ee->error_code == BadAccess)
|
||||
|| (ee->request_code == X_GrabKey &&
|
||||
ee->error_code == BadAccess)
|
||||
|| (ee->request_code == X_CopyArea &&
|
||||
ee->error_code == BadDrawable))
|
||||
return 0;
|
||||
}
|
||||
|
||||
fprintf(stderr, "tabbed: fatal error: request code=%d, error code=%d\n",
|
||||
ee->request_code, ee->error_code);
|
||||
|
@ -1230,28 +1273,29 @@ xerror(Display *dpy, XErrorEvent *ee) {
|
|||
}
|
||||
|
||||
void
|
||||
xsettitle(Window w, const char *str) {
|
||||
xsettitle(Window w, const char *str)
|
||||
{
|
||||
XTextProperty xtp;
|
||||
|
||||
if(XmbTextListToTextProperty(dpy, (char **)&str, 1, XCompoundTextStyle,
|
||||
&xtp) == Success) {
|
||||
if (XmbTextListToTextProperty(dpy, (char **)&str, 1,
|
||||
XCompoundTextStyle, &xtp) == Success) {
|
||||
XSetTextProperty(dpy, w, &xtp, wmatom[WMName]);
|
||||
XSetTextProperty(dpy, w, &xtp, XA_WM_NAME);
|
||||
XFree(xtp.value);
|
||||
}
|
||||
}
|
||||
|
||||
char *argv0;
|
||||
|
||||
void
|
||||
usage(void) {
|
||||
die("usage: %s [-dfhsv] [-g geometry] [-n name] [-p [s+/-]pos] [-r narg] "
|
||||
"[-o color] [-O color] [-t color] [-T color] [-u color] [-U color] "
|
||||
"command...\n", argv0);
|
||||
usage(void)
|
||||
{
|
||||
die("usage: %s [-dfhsv] [-g geometry] [-n name] [-p [s+/-]pos] "
|
||||
"[-r narg] [-o color] [-O color] [-t color] [-T color] "
|
||||
"[-u color] [-U color] command...\n", argv0);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[]) {
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
Bool detach = False;
|
||||
int replace = 0;
|
||||
char *pstr;
|
||||
|
@ -1273,6 +1317,12 @@ main(int argc, char *argv[]) {
|
|||
case 'n':
|
||||
wmname = EARGF(usage());
|
||||
break;
|
||||
case 'O':
|
||||
normfgcolor = EARGF(usage());
|
||||
break;
|
||||
case 'o':
|
||||
normbgcolor = EARGF(usage());
|
||||
break;
|
||||
case 'p':
|
||||
pstr = EARGF(usage());
|
||||
if (pstr[0] == 's') {
|
||||
|
@ -1288,30 +1338,24 @@ main(int argc, char *argv[]) {
|
|||
case 's':
|
||||
doinitspawn = False;
|
||||
break;
|
||||
case 'o':
|
||||
normbgcolor = EARGF(usage());
|
||||
break;
|
||||
case 'O':
|
||||
normfgcolor = EARGF(usage());
|
||||
case 'T':
|
||||
selfgcolor = EARGF(usage());
|
||||
break;
|
||||
case 't':
|
||||
selbgcolor = EARGF(usage());
|
||||
break;
|
||||
case 'T':
|
||||
selfgcolor = EARGF(usage());
|
||||
case 'U':
|
||||
urgfgcolor = EARGF(usage());
|
||||
break;
|
||||
case 'u':
|
||||
urgbgcolor = EARGF(usage());
|
||||
break;
|
||||
case 'U':
|
||||
urgfgcolor = EARGF(usage());
|
||||
break;
|
||||
case 'v':
|
||||
die("tabbed-"VERSION", © 2009-2016"
|
||||
" tabbed engineers, see LICENSE"
|
||||
" for details.\n");
|
||||
break;
|
||||
default:
|
||||
default: /* FALLTHROUGH */
|
||||
case 'h':
|
||||
usage();
|
||||
} ARGEND;
|
||||
|
@ -1324,9 +1368,9 @@ main(int argc, char *argv[]) {
|
|||
setcmd(argc, argv, replace);
|
||||
|
||||
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
|
||||
fprintf(stderr, "tabbed: no locale support\n");
|
||||
fprintf(stderr, "%s: no locale support\n", argv0);
|
||||
if (!(dpy = XOpenDisplay(NULL)))
|
||||
die("tabbed: cannot open display\n");
|
||||
die("%s: cannot open display\n", argv0);
|
||||
|
||||
setup();
|
||||
printf("0x%lx\n", win);
|
||||
|
@ -1348,4 +1392,3 @@ main(int argc, char *argv[]) {
|
|||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue