implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
This commit is contained in:
parent
1549faf3b9
commit
9cd686c93a
2
Makefile
2
Makefile
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
include config.mk
|
include config.mk
|
||||||
|
|
||||||
SRC = client.c dev.c draw.c event.c main.c util.c
|
SRC = bar.c client.c dev.c draw.c event.c main.c util.c
|
||||||
OBJ = ${SRC:.c=.o}
|
OBJ = ${SRC:.c=.o}
|
||||||
MAN1 = dwm.1
|
MAN1 = dwm.1
|
||||||
BIN = dwm
|
BIN = dwm
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
||||||
|
* See LICENSE file for license details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "dwm.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
draw_bar()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
dc.x = dc.y = 0;
|
||||||
|
dc.w = bw;
|
||||||
|
drawtext(NULL, False);
|
||||||
|
|
||||||
|
dc.w = 0;
|
||||||
|
for(i = 0; i < TLast; i++) {
|
||||||
|
dc.x += dc.w;
|
||||||
|
dc.w = textw(tags[i]) + dc.font.height;
|
||||||
|
if(i == tsel) {
|
||||||
|
swap((void **)&dc.fg, (void **)&dc.bg);
|
||||||
|
drawtext(tags[i], True);
|
||||||
|
swap((void **)&dc.fg, (void **)&dc.bg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
drawtext(tags[i], True);
|
||||||
|
}
|
||||||
|
if(sel) {
|
||||||
|
swap((void **)&dc.fg, (void **)&dc.bg);
|
||||||
|
dc.x += dc.w;
|
||||||
|
dc.w = textw(sel->name) + dc.font.height;
|
||||||
|
drawtext(sel->name, True);
|
||||||
|
swap((void **)&dc.fg, (void **)&dc.bg);
|
||||||
|
}
|
||||||
|
dc.w = textw(stext) + dc.font.height;
|
||||||
|
dc.x = bx + bw - dc.w;
|
||||||
|
drawtext(stext, False);
|
||||||
|
XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0);
|
||||||
|
XFlush(dpy);
|
||||||
|
}
|
30
client.c
30
client.c
|
@ -49,9 +49,9 @@ max(Arg *arg)
|
||||||
if(!sel)
|
if(!sel)
|
||||||
return;
|
return;
|
||||||
sel->x = sx;
|
sel->x = sx;
|
||||||
sel->y = sy;
|
sel->y = sy + bh;
|
||||||
sel->w = sw - 2 * sel->border;
|
sel->w = sw - 2 * sel->border;
|
||||||
sel->h = sh - 2 * sel->border;
|
sel->h = sh - 2 * sel->border - bh;
|
||||||
craise(sel);
|
craise(sel);
|
||||||
resize(sel, False);
|
resize(sel, False);
|
||||||
discard_events(EnterWindowMask);
|
discard_events(EnterWindowMask);
|
||||||
|
@ -67,6 +67,7 @@ view(Arg *arg)
|
||||||
|
|
||||||
for(c = clients; c; c = next(c->next))
|
for(c = clients; c; c = next(c->next))
|
||||||
draw_client(c);
|
draw_client(c);
|
||||||
|
draw_bar();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -131,7 +132,10 @@ tiling(Arg *arg)
|
||||||
if(c->tags[tsel] && !c->floating)
|
if(c->tags[tsel] && !c->floating)
|
||||||
n++;
|
n++;
|
||||||
|
|
||||||
h = (n > 1) ? sh / (n - 1) : sh;
|
if(n > 1)
|
||||||
|
h = (sh - bh) / (n - 1);
|
||||||
|
else
|
||||||
|
h = sh - bh;
|
||||||
|
|
||||||
for(i = 0, c = clients; c; c = c->next) {
|
for(i = 0, c = clients; c; c = c->next) {
|
||||||
if(c->tags[tsel]) {
|
if(c->tags[tsel]) {
|
||||||
|
@ -142,19 +146,19 @@ tiling(Arg *arg)
|
||||||
}
|
}
|
||||||
if(n == 1) {
|
if(n == 1) {
|
||||||
c->x = sx;
|
c->x = sx;
|
||||||
c->y = sy;
|
c->y = sy + bh;
|
||||||
c->w = sw - 2 * c->border;
|
c->w = sw - 2 * c->border;
|
||||||
c->h = sh - 2 * c->border;
|
c->h = sh - 2 * c->border - bh;
|
||||||
}
|
}
|
||||||
else if(i == 0) {
|
else if(i == 0) {
|
||||||
c->x = sx;
|
c->x = sx;
|
||||||
c->y = sy;
|
c->y = sy + bh;
|
||||||
c->w = mw - 2 * c->border;
|
c->w = mw - 2 * c->border;
|
||||||
c->h = sh - 2 * c->border;
|
c->h = sh - 2 * c->border - bh;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
c->x = sx + mw;
|
c->x = sx + mw;
|
||||||
c->y = sy + (i - 1) * h;
|
c->y = sy + (i - 1) * h + bh;
|
||||||
c->w = w - 2 * c->border;
|
c->w = w - 2 * c->border;
|
||||||
c->h = h - 2 * c->border;
|
c->h = h - 2 * c->border;
|
||||||
}
|
}
|
||||||
|
@ -373,9 +377,11 @@ manage(Window w, XWindowAttributes *wa)
|
||||||
c->win = w;
|
c->win = w;
|
||||||
c->tx = c->x = wa->x;
|
c->tx = c->x = wa->x;
|
||||||
c->ty = c->y = wa->y;
|
c->ty = c->y = wa->y;
|
||||||
|
if(c->y < bh)
|
||||||
|
c->ty = c->y += bh;
|
||||||
c->tw = c->w = wa->width;
|
c->tw = c->w = wa->width;
|
||||||
c->h = wa->height;
|
c->h = wa->height;
|
||||||
c->th = th;
|
c->th = bh;
|
||||||
c->border = 1;
|
c->border = 1;
|
||||||
c->proto = win_proto(c->win);
|
c->proto = win_proto(c->win);
|
||||||
update_size(c);
|
update_size(c);
|
||||||
|
@ -570,6 +576,7 @@ draw_client(Client *c)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
if(c == sel) {
|
if(c == sel) {
|
||||||
|
draw_bar();
|
||||||
XUnmapWindow(dpy, c->title);
|
XUnmapWindow(dpy, c->title);
|
||||||
XSetWindowBorder(dpy, c->win, dc.fg);
|
XSetWindowBorder(dpy, c->win, dc.fg);
|
||||||
return;
|
return;
|
||||||
|
@ -579,19 +586,18 @@ draw_client(Client *c)
|
||||||
XMapWindow(dpy, c->title);
|
XMapWindow(dpy, c->title);
|
||||||
|
|
||||||
dc.x = dc.y = 0;
|
dc.x = dc.y = 0;
|
||||||
dc.h = c->th;
|
|
||||||
|
|
||||||
dc.w = 0;
|
dc.w = 0;
|
||||||
for(i = 0; i < TLast; i++) {
|
for(i = 0; i < TLast; i++) {
|
||||||
if(c->tags[i]) {
|
if(c->tags[i]) {
|
||||||
dc.x += dc.w;
|
dc.x += dc.w;
|
||||||
dc.w = textw(c->tags[i]) + dc.font.height;
|
dc.w = textw(c->tags[i]) + dc.font.height;
|
||||||
draw(True, c->tags[i]);
|
drawtext(c->tags[i], True);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dc.x += dc.w;
|
dc.x += dc.w;
|
||||||
dc.w = textw(c->name) + dc.font.height;
|
dc.w = textw(c->name) + dc.font.height;
|
||||||
draw(True, c->name);
|
drawtext(c->name, True);
|
||||||
XCopyArea(dpy, dc.drawable, c->title, dc.gc,
|
XCopyArea(dpy, dc.drawable, c->title, dc.gc,
|
||||||
0, 0, c->tw, c->th, 0, 0);
|
0, 0, c->tw, c->th, 0, 0);
|
||||||
XFlush(dpy);
|
XFlush(dpy);
|
||||||
|
|
2
draw.c
2
draw.c
|
@ -30,7 +30,7 @@ drawborder(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
draw(Bool border, const char *text)
|
drawtext(const char *text, Bool border)
|
||||||
{
|
{
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
|
|
11
dwm.h
11
dwm.h
|
@ -88,19 +88,22 @@ struct Key {
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Display *dpy;
|
extern Display *dpy;
|
||||||
extern Window root;
|
extern Window root, barwin;
|
||||||
extern Atom wm_atom[WMLast], net_atom[NetLast];
|
extern Atom wm_atom[WMLast], net_atom[NetLast];
|
||||||
extern Cursor cursor[CurLast];
|
extern Cursor cursor[CurLast];
|
||||||
extern Bool running, issel;
|
extern Bool running, issel;
|
||||||
extern void (*handler[LASTEvent])(XEvent *);
|
extern void (*handler[LASTEvent])(XEvent *);
|
||||||
extern void (*arrange)(Arg *);
|
extern void (*arrange)(Arg *);
|
||||||
|
|
||||||
extern int tsel, screen, sx, sy, sw, sh, mw, th;
|
extern int tsel, screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
|
||||||
extern char *tags[TLast];
|
extern char *tags[TLast], stext[1024];
|
||||||
|
|
||||||
extern DC dc;
|
extern DC dc;
|
||||||
extern Client *clients, *sel;
|
extern Client *clients, *sel;
|
||||||
|
|
||||||
|
/* bar.c */
|
||||||
|
extern void draw_bar();
|
||||||
|
|
||||||
/* client.c */
|
/* client.c */
|
||||||
extern void manage(Window w, XWindowAttributes *wa);
|
extern void manage(Window w, XWindowAttributes *wa);
|
||||||
extern void unmanage(Client *c);
|
extern void unmanage(Client *c);
|
||||||
|
@ -126,7 +129,7 @@ extern void zoom(Arg *arg);
|
||||||
extern void gravitate(Client *c, Bool invert);
|
extern void gravitate(Client *c, Bool invert);
|
||||||
|
|
||||||
/* draw.c */
|
/* draw.c */
|
||||||
extern void draw(Bool border, const char *text);
|
extern void drawtext(const char *text, Bool border);
|
||||||
extern unsigned long initcolor(const char *colstr);
|
extern unsigned long initcolor(const char *colstr);
|
||||||
extern void initfont(const char *fontstr);
|
extern void initfont(const char *fontstr);
|
||||||
extern unsigned int textnw(char *text, unsigned int len);
|
extern unsigned int textnw(char *text, unsigned int len);
|
||||||
|
|
41
main.c
41
main.c
|
@ -6,6 +6,7 @@
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <X11/cursorfont.h>
|
#include <X11/cursorfont.h>
|
||||||
#include <X11/Xatom.h>
|
#include <X11/Xatom.h>
|
||||||
|
@ -34,7 +35,8 @@ Bool running = True;
|
||||||
Bool issel;
|
Bool issel;
|
||||||
|
|
||||||
int tsel = Tdev; /* default tag */
|
int tsel = Tdev; /* default tag */
|
||||||
int screen, sx, sy, sw, sh, mw, th;
|
int screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
|
||||||
|
char stext[1024];
|
||||||
|
|
||||||
DC dc = {0};
|
DC dc = {0};
|
||||||
Client *clients = NULL;
|
Client *clients = NULL;
|
||||||
|
@ -42,7 +44,7 @@ Client *sel = NULL;
|
||||||
|
|
||||||
static Bool other_wm_running;
|
static Bool other_wm_running;
|
||||||
static const char version[] =
|
static const char version[] =
|
||||||
"dwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
|
"dwm-" VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
|
||||||
static int (*x_error_handler) (Display *, XErrorEvent *);
|
static int (*x_error_handler) (Display *, XErrorEvent *);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -219,12 +221,6 @@ main(int argc, char *argv[])
|
||||||
if(other_wm_running)
|
if(other_wm_running)
|
||||||
error("dwm: another window manager is already running\n");
|
error("dwm: another window manager is already running\n");
|
||||||
|
|
||||||
sx = sy = 0;
|
|
||||||
sw = DisplayWidth(dpy, screen);
|
|
||||||
sh = DisplayHeight(dpy, screen);
|
|
||||||
mw = (sw * MASTERW) / 100;
|
|
||||||
issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
|
|
||||||
|
|
||||||
XSetErrorHandler(0);
|
XSetErrorHandler(0);
|
||||||
x_error_handler = XSetErrorHandler(error_handler);
|
x_error_handler = XSetErrorHandler(error_handler);
|
||||||
|
|
||||||
|
@ -233,11 +229,9 @@ main(int argc, char *argv[])
|
||||||
wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
|
wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
|
||||||
net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
|
net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
|
||||||
net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
|
net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
|
||||||
|
|
||||||
XChangeProperty(dpy, root, net_atom[NetSupported], XA_ATOM, 32,
|
XChangeProperty(dpy, root, net_atom[NetSupported], XA_ATOM, 32,
|
||||||
PropModeReplace, (unsigned char *) net_atom, NetLast);
|
PropModeReplace, (unsigned char *) net_atom, NetLast);
|
||||||
|
|
||||||
|
|
||||||
/* init cursors */
|
/* init cursors */
|
||||||
cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
|
cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
|
||||||
cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
|
cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
|
||||||
|
@ -251,17 +245,38 @@ main(int argc, char *argv[])
|
||||||
dc.border = initcolor(BORDERCOLOR);
|
dc.border = initcolor(BORDERCOLOR);
|
||||||
initfont(FONT);
|
initfont(FONT);
|
||||||
|
|
||||||
th = dc.font.height + 4;
|
sx = sy = 0;
|
||||||
|
sw = DisplayWidth(dpy, screen);
|
||||||
|
sh = DisplayHeight(dpy, screen);
|
||||||
|
mw = (sw * MASTERW) / 100;
|
||||||
|
|
||||||
dc.drawable = XCreatePixmap(dpy, root, sw, th, DefaultDepth(dpy, screen));
|
wa.override_redirect = 1;
|
||||||
dc.gc = XCreateGC(dpy, root, 0, 0);
|
wa.background_pixmap = ParentRelative;
|
||||||
|
wa.event_mask = ExposureMask;
|
||||||
|
|
||||||
|
bx = by = 0;
|
||||||
|
bw = sw;
|
||||||
|
dc.h = bh = dc.font.height + 4;
|
||||||
|
barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, screen),
|
||||||
|
CopyFromParent, DefaultVisual(dpy, screen),
|
||||||
|
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
|
||||||
|
XDefineCursor(dpy, barwin, cursor[CurNormal]);
|
||||||
|
XMapRaised(dpy, barwin);
|
||||||
|
|
||||||
|
issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
|
||||||
|
|
||||||
wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
|
wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
|
||||||
| LeaveWindowMask;
|
| LeaveWindowMask;
|
||||||
wa.cursor = cursor[CurNormal];
|
wa.cursor = cursor[CurNormal];
|
||||||
|
|
||||||
XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
|
XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
|
||||||
|
|
||||||
|
dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
|
||||||
|
dc.gc = XCreateGC(dpy, root, 0, 0);
|
||||||
|
|
||||||
|
strcpy(stext, "dwm-"VERSION);
|
||||||
scan_wins();
|
scan_wins();
|
||||||
|
draw_bar();
|
||||||
|
|
||||||
while(running) {
|
while(running) {
|
||||||
XNextEvent(dpy, &ev);
|
XNextEvent(dpy, &ev);
|
||||||
|
|
Loading…
Reference in New Issue