#include <err.h>
#include <locale.h>
#include <unistd.h>
+#include <time.h>
+#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
Display *display;
Window root;
+/* status bar */
+int bar_enabled = 1;
+int bar_height = 12;
+Window bar_window;
+GC bar_gc;
+XGCValues bar_gcv;
+XFontStruct *bar_fs;
+char bar_text[128];
+
struct ws_win {
TAILQ_ENTRY(ws_win) entry;
Window id;
};
void
+bar_print(void)
+{
+ time_t tmt;
+ struct tm tm;
+
+ /* clear old text */
+ XSetForeground(display, bar_gc, 0x000000);
+ XDrawString(display, bar_window, bar_gc, 4, bar_fs->ascent, bar_text,
+ strlen(bar_text));
+
+ /* draw new text */
+ time(&tmt);
+ localtime_r(&tmt, &tm);
+ strftime(bar_text, sizeof bar_text, "%a %b %d %R %Z %Y", &tm);
+ XSetForeground(display, bar_gc, 0xa0a0a0);
+ XDrawString(display, bar_window, bar_gc, 4, bar_fs->ascent, bar_text,
+ strlen(bar_text));
+ XSync(display, False);
+}
+void
quit(union arg *args)
{
DNPRINTF(SWM_D_MISC, "quit\n");
void
focus_win(struct ws_win *win)
{
- DNPRINTF(SWM_D_FOCUS, "focus_win: id: %d\n", win->id);
+ DNPRINTF(SWM_D_FOCUS, "focus_win: id: %lu\n", win->id);
XSetWindowBorder(display, win->id, col_focus);
XSetInputFocus(display, win->id, RevertToPointerRoot, CurrentTime);
ws[current_ws].focus = win;
void
unfocus_win(struct ws_win *win)
{
- DNPRINTF(SWM_D_FOCUS, "unfocus_win: id: %d\n", win->id);
+ DNPRINTF(SWM_D_FOCUS, "unfocus_win: id: %lu\n", win->id);
XSetWindowBorder(display, win->id, col_unfocus);
if (ws[current_ws].focus == win)
ws[current_ws].focus = NULL;
{
int wsid = args->id;
struct ws_win *win;
- Window winfocus;
DNPRINTF(SWM_D_WS, "switchws: %d\n", wsid + 1);
{
XWindowChanges wc;
struct ws_win wf, *win, *winfocus = &wf;
- int i, h, w, x, y, winno, hrh;
+ int i, h, w, x, y, hrh;
DNPRINTF(SWM_D_EVENT, "stack: workspace: %d\n", current_ws);
hrh = 0;
x = 0;
- y = 0;
+ y = bar_height;
h = height;
i = 0;
TAILQ_FOREACH (win, &ws[current_ws].winlist, entry) {
{
struct ws_win *tmpwin = TAILQ_FIRST(&ws[current_ws].winlist);
- DNPRINTF(SWM_D_MISC, "swap_to_main: win: %d\n", ws[current_ws].focus->id);
+ DNPRINTF(SWM_D_MISC, "swap_to_main: win: %lu\n",
+ ws[current_ws].focus->id);
+
TAILQ_REMOVE(&ws[current_ws].winlist, tmpwin, entry);
TAILQ_INSERT_AFTER(&ws[current_ws].winlist, ws[current_ws].focus,
tmpwin, entry);
void
expose(XEvent *e)
{
- XExposeEvent *ev = &e->xexpose;
-
- DNPRINTF(SWM_D_EVENT, "expose: window: %d\n", ev->window);
+ DNPRINTF(SWM_D_EVENT, "expose: window: %lu\n", e->xexpose.window);
}
void
KeySym keysym;
XKeyEvent *ev = &e->xkey;
- DNPRINTF(SWM_D_EVENT, "keypress: window: %d\n", ev->window);
+ DNPRINTF(SWM_D_EVENT, "keypress: window: %lu\n", ev->window);
keysym = XKeycodeToKeysym(display, (KeyCode)ev->keycode, 0);
for(i = 0; i < LENGTH(keys); i++)
buttonpress(XEvent *e)
{
XButtonPressedEvent *ev = &e->xbutton;
+#ifdef SWM_CLICKTOFOCUS
struct ws_win *win;
+#endif
+
- DNPRINTF(SWM_D_EVENT, "buttonpress: window: %d\n", ev->window);
+ DNPRINTF(SWM_D_EVENT, "buttonpress: window: %lu\n", ev->window);
if (ev->window == root)
return;
if (ev->window == ws[current_ws].focus->id)
return;
-#if 0
+#ifdef SWM_CLICKTOFOCUS
TAILQ_FOREACH(win, &ws[current_ws].winlist, entry)
if (win->id == ev->window) {
/* focus in the clicked window */
XConfigureRequestEvent *ev = &e->xconfigurerequest;
struct ws_win *win;
- DNPRINTF(SWM_D_EVENT, "configurerequest: window: %d\n", ev->window);
+ DNPRINTF(SWM_D_EVENT, "configurerequest: window: %lu\n", ev->window);
XSelectInput(display, ev->window, ButtonPressMask | EnterWindowMask |
FocusChangeMask);
void
configurenotify(XEvent *e)
{
- XConfigureEvent *ev = &e->xconfigure;
-
- DNPRINTF(SWM_D_EVENT, "configurenotify: window: %d\n", ev->window);
+ DNPRINTF(SWM_D_EVENT, "configurenotify: window: %lu\n",
+ e->xconfigure.window);
}
void
destroynotify(XEvent *e)
{
- size_t sz;
struct ws_win *win;
XDestroyWindowEvent *ev = &e->xdestroywindow;
- DNPRINTF(SWM_D_EVENT, "destroynotify: window %d\n", ev->window);
+ DNPRINTF(SWM_D_EVENT, "destroynotify: window %lu\n", ev->window);
TAILQ_FOREACH (win, &ws[current_ws].winlist, entry) {
if (ev->window == win->id) {
XCrossingEvent *ev = &e->xcrossing;
struct ws_win *win;
- DNPRINTF(SWM_D_EVENT, "enternotify: window: %d\n", ev->window);
+ DNPRINTF(SWM_D_EVENT, "enternotify: window: %lu\n", ev->window);
if((ev->mode != NotifyNormal || ev->detail == NotifyInferior) &&
ev->window != root)
{
XFocusChangeEvent *ev = &e->xfocus;
- DNPRINTF(SWM_D_EVENT, "focusin: window: %d\n", ev->window);
+ DNPRINTF(SWM_D_EVENT, "focusin: window: %lu\n", ev->window);
if (ev->window == root)
return;
* click to focus
*/
/*
- DNPRINTF(SWM_D_EVENT, "focusin: window: %d grabbing\n", ev->window);
+ DNPRINTF(SWM_D_EVENT, "focusin: window: %lu grabbing\n", ev->window);
XGrabButton(display, Button1, AnyModifier, ev->window, False,
ButtonPress, GrabModeAsync, GrabModeSync, None, None);
*/
{
XMappingEvent *ev = &e->xmapping;
- DNPRINTF(SWM_D_EVENT, "mappingnotify: window: %d\n", ev->window);
+ DNPRINTF(SWM_D_EVENT, "mappingnotify: window: %lu\n", ev->window);
XRefreshKeyboardMapping(ev);
if(ev->request == MappingKeyboard)
void
maprequest(XEvent *e)
{
- XMapRequestEvent *ev = &e->xmaprequest;
-
- DNPRINTF(SWM_D_EVENT, "maprequest: window: %d\n", ev->window);
+ DNPRINTF(SWM_D_EVENT, "maprequest: window: %lu\n",
+ e->xmaprequest.window);
}
void
propertynotify(XEvent *e)
{
- XPropertyEvent *ev = &e->xproperty;
-
- DNPRINTF(SWM_D_EVENT, "propertynotify: window: %d\n", ev->window);
+ DNPRINTF(SWM_D_EVENT, "propertynotify: window: %lu\n",
+ e->xproperty.window);
}
void
unmapnotify(XEvent *e)
{
- XUnmapEvent *ev = &e->xunmap;
-
- DNPRINTF(SWM_D_EVENT, "unmapnotify: window: %d\n", ev->window);
+ DNPRINTF(SWM_D_EVENT, "unmapnotify: window: %lu\n", e->xunmap.window);
}
void (*handler[LASTEvent])(XEvent *) = {
TAILQ_INIT(&ws[i].winlist);
}
+ /* setup status bar */
+ bar_fs = XLoadQueryFont(display,
+ "-*-terminus-*-*-*-*-*-*-*-*-*-*-*-*");
+ if (bar_fs == NULL) {
+ /* load a font that is default */
+ bar_fs = XLoadQueryFont(display,
+ "-*-times-medium-r-*-*-*-*-*-*-*-*-*-*");
+ if (bar_fs == NULL)
+ errx(1, "couldn't load font");
+ }
+ bar_height = bar_fs->ascent + bar_fs->descent + 3;
+
XSelectInput(display, root, SubstructureRedirectMask |
SubstructureNotifyMask | ButtonPressMask | KeyPressMask |
EnterWindowMask | LeaveWindowMask | StructureNotifyMask |
grabkeys();
+ bar_window = XCreateSimpleWindow(display, root, 0, 0, width,
+ bar_height - 2, 1, 0x008080, 0x000000);
+ bar_gc = XCreateGC(display, bar_window, 0, &bar_gcv);
+ XSetFont(display, bar_gc, bar_fs->fid);
+ if (bar_enabled) {
+ height -= bar_height; /* correct screen height */
+ XMapWindow(display, bar_window);
+ }
+ bar_print();
+
while (running) {
XNextEvent(display, &e);
if (handler[e.type])