Browse Source

implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm

config
Anselm R. Garbe 18 years ago
parent
commit
9cd686c93a
6 changed files with 95 additions and 31 deletions
  1. +1
    -1
      Makefile
  2. +40
    -0
      bar.c
  3. +18
    -12
      client.c
  4. +1
    -1
      draw.c
  5. +7
    -4
      dwm.h
  6. +28
    -13
      main.c

+ 1
- 1
Makefile View File

@ -3,7 +3,7 @@
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}
MAN1 = dwm.1
BIN = dwm


+ 40
- 0
bar.c View File

@ -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);
}

+ 18
- 12
client.c View File

@ -49,9 +49,9 @@ max(Arg *arg)
if(!sel)
return;
sel->x = sx;
sel->y = sy;
sel->y = sy + bh;
sel->w = sw - 2 * sel->border;
sel->h = sh - 2 * sel->border;
sel->h = sh - 2 * sel->border - bh;
craise(sel);
resize(sel, False);
discard_events(EnterWindowMask);
@ -67,6 +67,7 @@ view(Arg *arg)
for(c = clients; c; c = next(c->next))
draw_client(c);
draw_bar();
}
void
@ -131,7 +132,10 @@ tiling(Arg *arg)
if(c->tags[tsel] && !c->floating)
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) {
if(c->tags[tsel]) {
@ -142,19 +146,19 @@ tiling(Arg *arg)
}
if(n == 1) {
c->x = sx;
c->y = sy;
c->y = sy + bh;
c->w = sw - 2 * c->border;
c->h = sh - 2 * c->border;
c->h = sh - 2 * c->border - bh;
}
else if(i == 0) {
c->x = sx;
c->y = sy;
c->y = sy + bh;
c->w = mw - 2 * c->border;
c->h = sh - 2 * c->border;
c->h = sh - 2 * c->border - bh;
}
else {
c->x = sx + mw;
c->y = sy + (i - 1) * h;
c->y = sy + (i - 1) * h + bh;
c->w = w - 2 * c->border;
c->h = h - 2 * c->border;
}
@ -373,9 +377,11 @@ manage(Window w, XWindowAttributes *wa)
c->win = w;
c->tx = c->x = wa->x;
c->ty = c->y = wa->y;
if(c->y < bh)
c->ty = c->y += bh;
c->tw = c->w = wa->width;
c->h = wa->height;
c->th = th;
c->th = bh;
c->border = 1;
c->proto = win_proto(c->win);
update_size(c);
@ -570,6 +576,7 @@ draw_client(Client *c)
{
int i;
if(c == sel) {
draw_bar();
XUnmapWindow(dpy, c->title);
XSetWindowBorder(dpy, c->win, dc.fg);
return;
@ -579,19 +586,18 @@ draw_client(Client *c)
XMapWindow(dpy, c->title);
dc.x = dc.y = 0;
dc.h = c->th;
dc.w = 0;
for(i = 0; i < TLast; i++) {
if(c->tags[i]) {
dc.x += dc.w;
dc.w = textw(c->tags[i]) + dc.font.height;
draw(True, c->tags[i]);
drawtext(c->tags[i], True);
}
}
dc.x += dc.w;
dc.w = textw(c->name) + dc.font.height;
draw(True, c->name);
drawtext(c->name, True);
XCopyArea(dpy, dc.drawable, c->title, dc.gc,
0, 0, c->tw, c->th, 0, 0);
XFlush(dpy);


+ 1
- 1
draw.c View File

@ -30,7 +30,7 @@ drawborder(void)
}
void
draw(Bool border, const char *text)
drawtext(const char *text, Bool border)
{
int x, y, w, h;
unsigned int len;


+ 7
- 4
dwm.h View File

@ -88,19 +88,22 @@ struct Key {
};
extern Display *dpy;
extern Window root;
extern Window root, barwin;
extern Atom wm_atom[WMLast], net_atom[NetLast];
extern Cursor cursor[CurLast];
extern Bool running, issel;
extern void (*handler[LASTEvent])(XEvent *);
extern void (*arrange)(Arg *);
extern int tsel, screen, sx, sy, sw, sh, mw, th;
extern char *tags[TLast];
extern int tsel, screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
extern char *tags[TLast], stext[1024];
extern DC dc;
extern Client *clients, *sel;
/* bar.c */
extern void draw_bar();
/* client.c */
extern void manage(Window w, XWindowAttributes *wa);
extern void unmanage(Client *c);
@ -126,7 +129,7 @@ extern void zoom(Arg *arg);
extern void gravitate(Client *c, Bool invert);
/* 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 void initfont(const char *fontstr);
extern unsigned int textnw(char *text, unsigned int len);


+ 28
- 13
main.c View File

@ -6,6 +6,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/cursorfont.h>
#include <X11/Xatom.h>
@ -34,7 +35,8 @@ Bool running = True;
Bool issel;
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};
Client *clients = NULL;
@ -42,7 +44,7 @@ Client *sel = NULL;
static Bool other_wm_running;
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 void
@ -219,12 +221,6 @@ main(int argc, char *argv[])
if(other_wm_running)
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);
x_error_handler = XSetErrorHandler(error_handler);
@ -233,11 +229,9 @@ main(int argc, char *argv[])
wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
XChangeProperty(dpy, root, net_atom[NetSupported], XA_ATOM, 32,
PropModeReplace, (unsigned char *) net_atom, NetLast);
/* init cursors */
cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
@ -251,17 +245,38 @@ main(int argc, char *argv[])
dc.border = initcolor(BORDERCOLOR);
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));
dc.gc = XCreateGC(dpy, root, 0, 0);
wa.override_redirect = 1;
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 \
| LeaveWindowMask;
wa.cursor = cursor[CurNormal];
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();
draw_bar();
while(running) {
XNextEvent(dpy, &ev);


Loading…
Cancel
Save