simplified several portions of code through replacing rect structs with x,y,h,w counterparts (much more readable)
This commit is contained in:
parent
7696c89c90
commit
dfd84f9bf3
17
bar.c
17
bar.c
@ -8,23 +8,22 @@
|
|||||||
void
|
void
|
||||||
draw_bar()
|
draw_bar()
|
||||||
{
|
{
|
||||||
brush.rect = barrect;
|
brush.x = brush.y = 0;
|
||||||
brush.rect.x = brush.rect.y = 0;
|
brush.w = bw;
|
||||||
|
brush.h = bh;
|
||||||
draw(dpy, &brush, False, NULL);
|
draw(dpy, &brush, False, NULL);
|
||||||
|
|
||||||
if(stack) {
|
if(stack) {
|
||||||
brush.rect.width = textwidth(&brush.font, stack->name) + labelheight(&brush.font);
|
brush.w = textw(&brush.font, stack->name) + bh;
|
||||||
swap((void **)&brush.fg, (void **)&brush.bg);
|
swap((void **)&brush.fg, (void **)&brush.bg);
|
||||||
draw(dpy, &brush, True, stack->name);
|
draw(dpy, &brush, True, stack->name);
|
||||||
swap((void **)&brush.fg, (void **)&brush.bg);
|
swap((void **)&brush.fg, (void **)&brush.bg);
|
||||||
brush.rect.x += brush.rect.width;
|
brush.x += brush.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
brush.rect.width = textwidth(&brush.font, statustext) + labelheight(&brush.font);
|
brush.w = textw(&brush.font, statustext) + bh;
|
||||||
brush.rect.x = barrect.x + barrect.width - brush.rect.width;
|
brush.x = bx + bw - brush.w;
|
||||||
draw(dpy, &brush, False, statustext);
|
draw(dpy, &brush, False, statustext);
|
||||||
|
XCopyArea(dpy, brush.drawable, barwin, brush.gc, 0, 0, bw, bh, 0, 0);
|
||||||
XCopyArea(dpy, brush.drawable, barwin, brush.gc, 0, 0, barrect.width,
|
|
||||||
barrect.height, 0, 0);
|
|
||||||
XFlush(dpy);
|
XFlush(dpy);
|
||||||
}
|
}
|
||||||
|
64
client.c
64
client.c
@ -10,7 +10,16 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "wm.h"
|
#include "wm.h"
|
||||||
|
|
||||||
#define CLIENT_MASK (StructureNotifyMask | PropertyChangeMask | EnterWindowMask)
|
static void
|
||||||
|
resize_title(Client *c)
|
||||||
|
{
|
||||||
|
c->tw = textw(&brush.font, c->name) + bh;
|
||||||
|
if(c->tw > c->w)
|
||||||
|
c->tw = c->w + 2;
|
||||||
|
c->tx = c->x + c->w - c->tw + 2;
|
||||||
|
c->ty = c->y;
|
||||||
|
XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
update_name(Client *c)
|
update_name(Client *c)
|
||||||
@ -37,6 +46,7 @@ update_name(Client *c)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
XFree(name.value);
|
XFree(name.value);
|
||||||
|
resize_title(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -73,27 +83,38 @@ update_size(Client *c)
|
|||||||
c->minw = c->minh = 0;
|
c->minw = c->minh = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
raise(Client *c)
|
||||||
|
{
|
||||||
|
XRaiseWindow(dpy, c->win);
|
||||||
|
XRaiseWindow(dpy, c->title);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
lower(Client *c)
|
||||||
|
{
|
||||||
|
XLowerWindow(dpy, c->title);
|
||||||
|
XLowerWindow(dpy, c->win);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
focus(Client *c)
|
focus(Client *c)
|
||||||
{
|
{
|
||||||
Client **l, *old;
|
Client **l, *old;
|
||||||
|
|
||||||
old = stack;
|
old = stack;
|
||||||
for(l=&stack; *l && *l != c; l=&(*l)->snext);
|
for(l = &stack; *l && *l != c; l = &(*l)->snext);
|
||||||
eassert(*l == c);
|
eassert(*l == c);
|
||||||
*l = c->snext;
|
*l = c->snext;
|
||||||
c->snext = stack;
|
c->snext = stack;
|
||||||
stack = c;
|
stack = c;
|
||||||
XRaiseWindow(dpy, c->win);
|
|
||||||
XRaiseWindow(dpy, c->title);
|
|
||||||
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
|
|
||||||
if(old && old != c) {
|
if(old && old != c) {
|
||||||
XMapWindow(dpy, old->title);
|
XMapWindow(dpy, old->title);
|
||||||
draw_client(old);
|
draw_client(old);
|
||||||
}
|
}
|
||||||
XUnmapWindow(dpy, c->title);
|
XUnmapWindow(dpy, c->title);
|
||||||
draw_bar();
|
draw_client(old);
|
||||||
discard_events(EnterWindowMask);
|
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
|
||||||
XFlush(dpy);
|
XFlush(dpy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,13 +128,16 @@ 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 = barrect.height;
|
c->th = bh;
|
||||||
update_size(c);
|
update_size(c);
|
||||||
XSetWindowBorderWidth(dpy, c->win, 1);
|
XSetWindowBorderWidth(dpy, c->win, 1);
|
||||||
XSetWindowBorder(dpy, c->win, brush.border);
|
XSetWindowBorder(dpy, c->win, brush.border);
|
||||||
XSelectInput(dpy, c->win, CLIENT_MASK);
|
XSelectInput(dpy, c->win,
|
||||||
|
StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
|
||||||
XGetTransientForHint(dpy, c->win, &c->trans);
|
XGetTransientForHint(dpy, c->win, &c->trans);
|
||||||
twa.override_redirect = 1;
|
twa.override_redirect = 1;
|
||||||
twa.background_pixmap = ParentRelative;
|
twa.background_pixmap = ParentRelative;
|
||||||
@ -130,8 +154,8 @@ manage(Window w, XWindowAttributes *wa)
|
|||||||
*l = c;
|
*l = c;
|
||||||
c->snext = stack;
|
c->snext = stack;
|
||||||
stack = c;
|
stack = c;
|
||||||
XMapWindow(dpy, c->win);
|
XMapRaised(dpy, c->win);
|
||||||
XMapWindow(dpy, c->title);
|
XMapRaised(dpy, c->title);
|
||||||
XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
|
XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
|
||||||
GrabModeAsync, GrabModeSync, None, None);
|
GrabModeAsync, GrabModeSync, None, None);
|
||||||
XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
|
XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
|
||||||
@ -147,6 +171,7 @@ resize(Client *c)
|
|||||||
{
|
{
|
||||||
XConfigureEvent e;
|
XConfigureEvent e;
|
||||||
|
|
||||||
|
resize_title(c);
|
||||||
XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
|
XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
|
||||||
e.type = ConfigureNotify;
|
e.type = ConfigureNotify;
|
||||||
e.event = c->win;
|
e.event = c->win;
|
||||||
@ -158,9 +183,7 @@ resize(Client *c)
|
|||||||
e.border_width = 0;
|
e.border_width = 0;
|
||||||
e.above = None;
|
e.above = None;
|
||||||
e.override_redirect = False;
|
e.override_redirect = False;
|
||||||
XSelectInput(dpy, c->win, CLIENT_MASK & ~StructureNotifyMask);
|
|
||||||
XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
|
XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
|
||||||
XSelectInput(dpy, c->win, CLIENT_MASK);
|
|
||||||
XFlush(dpy);
|
XFlush(dpy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,17 +242,14 @@ getclient(Window w)
|
|||||||
void
|
void
|
||||||
draw_client(Client *c)
|
draw_client(Client *c)
|
||||||
{
|
{
|
||||||
if(c == stack)
|
if(c == stack) {
|
||||||
draw_bar();
|
draw_bar();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
c->tw = textwidth(&brush.font, c->name) + labelheight(&brush.font);
|
brush.x = brush.y = 0;
|
||||||
c->tx = c->x + c->w - c->tw + 2;
|
brush.w = c->tw;
|
||||||
c->ty = c->y;
|
brush.h = c->th;
|
||||||
XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
|
|
||||||
|
|
||||||
brush.rect.x = brush.rect.y = 0;
|
|
||||||
brush.rect.width = c->tw;
|
|
||||||
brush.rect.height = c->th;
|
|
||||||
|
|
||||||
draw(dpy, &brush, True, c->name);
|
draw(dpy, &brush, True, c->name);
|
||||||
XCopyArea(dpy, brush.drawable, c->title, brush.gc,
|
XCopyArea(dpy, brush.drawable, c->title, brush.gc,
|
||||||
|
12
cmd.c
12
cmd.c
@ -23,16 +23,18 @@ void
|
|||||||
sel(void *aux)
|
sel(void *aux)
|
||||||
{
|
{
|
||||||
const char *arg = aux;
|
const char *arg = aux;
|
||||||
Client *c;
|
Client *c = NULL;
|
||||||
|
|
||||||
if(!arg || !stack)
|
if(!arg || !stack)
|
||||||
return;
|
return;
|
||||||
if(!strncmp(arg, "next", 5))
|
if(!strncmp(arg, "next", 5))
|
||||||
focus(stack->snext ? stack->snext : stack);
|
c = stack->snext ? stack->snext : stack;
|
||||||
else if(!strncmp(arg, "prev", 5)) {
|
else if(!strncmp(arg, "prev", 5))
|
||||||
for(c = stack; c && c->snext; c = c->snext);
|
for(c = stack; c && c->snext; c = c->snext);
|
||||||
focus(c ? c : stack);
|
if(!c)
|
||||||
}
|
c = stack;
|
||||||
|
raise(c);
|
||||||
|
focus(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
8
config.h
8
config.h
@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#define FONT "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*"
|
#define FONT "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*"
|
||||||
#define BGCOLOR "#0c0c33"
|
#define BGCOLOR "#666699"
|
||||||
#define FGCOLOR "#b2c8cd"
|
#define FGCOLOR "#ffffff"
|
||||||
#define BORDERCOLOR "#3030c0"
|
#define BORDERCOLOR "#9999CC"
|
||||||
#define STATUSDELAY 10 /* milliseconds */
|
#define STATUSDELAY 10 /* seconds */
|
||||||
|
45
draw.c
45
draw.c
@ -15,16 +15,16 @@ drawborder(Display *dpy, Brush *b)
|
|||||||
XPoint points[5];
|
XPoint points[5];
|
||||||
XSetLineAttributes(dpy, b->gc, 1, LineSolid, CapButt, JoinMiter);
|
XSetLineAttributes(dpy, b->gc, 1, LineSolid, CapButt, JoinMiter);
|
||||||
XSetForeground(dpy, b->gc, b->border);
|
XSetForeground(dpy, b->gc, b->border);
|
||||||
points[0].x = b->rect.x;
|
points[0].x = b->x;
|
||||||
points[0].y = b->rect.y;
|
points[0].y = b->y;
|
||||||
points[1].x = b->rect.width - 1;
|
points[1].x = b->w - 1;
|
||||||
points[1].y = 0;
|
points[1].y = 0;
|
||||||
points[2].x = 0;
|
points[2].x = 0;
|
||||||
points[2].y = b->rect.height - 1;
|
points[2].y = b->h - 1;
|
||||||
points[3].x = -(b->rect.width - 1);
|
points[3].x = -(b->w - 1);
|
||||||
points[3].y = 0;
|
points[3].y = 0;
|
||||||
points[4].x = 0;
|
points[4].x = 0;
|
||||||
points[4].y = -(b->rect.height - 1);
|
points[4].y = -(b->h - 1);
|
||||||
XDrawLines(dpy, b->drawable, b->gc, points, 5, CoordModePrevious);
|
XDrawLines(dpy, b->drawable, b->gc, points, 5, CoordModePrevious);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,9 +34,10 @@ draw(Display *dpy, Brush *b, Bool border, const char *text)
|
|||||||
unsigned int x, y, w, h, len;
|
unsigned int x, y, w, h, len;
|
||||||
static char buf[256];
|
static char buf[256];
|
||||||
XGCValues gcv;
|
XGCValues gcv;
|
||||||
|
XRectangle r = { b->x, b->y, b->w, b->h };
|
||||||
|
|
||||||
XSetForeground(dpy, b->gc, b->bg);
|
XSetForeground(dpy, b->gc, b->bg);
|
||||||
XFillRectangles(dpy, b->drawable, b->gc, &b->rect, 1);
|
XFillRectangles(dpy, b->drawable, b->gc, &r, 1);
|
||||||
|
|
||||||
if(border)
|
if(border)
|
||||||
drawborder(dpy, b);
|
drawborder(dpy, b);
|
||||||
@ -51,14 +52,14 @@ draw(Display *dpy, Brush *b, Bool border, const char *text)
|
|||||||
buf[len] = 0;
|
buf[len] = 0;
|
||||||
|
|
||||||
h = b->font.ascent + b->font.descent;
|
h = b->font.ascent + b->font.descent;
|
||||||
y = b->rect.y + (b->rect.height / 2) - (h / 2) + b->font.ascent;
|
y = b->y + (b->h / 2) - (h / 2) + b->font.ascent;
|
||||||
x = b->rect.x + (h / 2);
|
x = b->x + (h / 2);
|
||||||
|
|
||||||
/* shorten text if necessary */
|
/* shorten text if necessary */
|
||||||
while(len && (w = textwidth_l(&b->font, buf, len)) > b->rect.width - h)
|
while(len && (w = textnw(&b->font, buf, len)) > b->w - h)
|
||||||
buf[--len] = 0;
|
buf[--len] = 0;
|
||||||
|
|
||||||
if(w > b->rect.width)
|
if(w > b->w)
|
||||||
return; /* too long */
|
return; /* too long */
|
||||||
|
|
||||||
gcv.foreground = b->fg;
|
gcv.foreground = b->fg;
|
||||||
@ -94,20 +95,26 @@ loadcolors(Display *dpy, int screen, Brush *b,
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
textwidth_l(Fnt *font, char *text, unsigned int len)
|
textnw(Fnt *font, char *text, unsigned int len)
|
||||||
{
|
{
|
||||||
|
XRectangle r;
|
||||||
if(font->set) {
|
if(font->set) {
|
||||||
XRectangle r;
|
XmbTextExtents(font->set, text, len, NULL, &r);
|
||||||
XmbTextExtents(font->set, text, len, 0, &r);
|
|
||||||
return r.width;
|
return r.width;
|
||||||
}
|
}
|
||||||
return XTextWidth(font->xfont, text, len);
|
return XTextWidth(font->xfont, text, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
textwidth(Fnt *font, char *text)
|
textw(Fnt *font, char *text)
|
||||||
{
|
{
|
||||||
return textwidth_l(font, text, strlen(text));
|
return textnw(font, text, strlen(text));
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
texth(Fnt *font)
|
||||||
|
{
|
||||||
|
return font->height + 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -162,9 +169,3 @@ loadfont(Display *dpy, Fnt *font, const char *fontstr)
|
|||||||
}
|
}
|
||||||
font->height = font->ascent + font->descent;
|
font->height = font->ascent + font->descent;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
|
||||||
labelheight(Fnt *font)
|
|
||||||
{
|
|
||||||
return font->height + 4;
|
|
||||||
}
|
|
||||||
|
8
draw.h
8
draw.h
@ -20,7 +20,7 @@ struct Fnt {
|
|||||||
struct Brush {
|
struct Brush {
|
||||||
GC gc;
|
GC gc;
|
||||||
Drawable drawable;
|
Drawable drawable;
|
||||||
XRectangle rect;
|
int x, y, w, h;
|
||||||
Fnt font;
|
Fnt font;
|
||||||
unsigned long bg;
|
unsigned long bg;
|
||||||
unsigned long fg;
|
unsigned long fg;
|
||||||
@ -31,6 +31,6 @@ extern void draw(Display *dpy, Brush *b, Bool border, const char *text);
|
|||||||
extern void loadcolors(Display *dpy, int screen, Brush *b,
|
extern void loadcolors(Display *dpy, int screen, Brush *b,
|
||||||
const char *bg, const char *fg, const char *bo);
|
const char *bg, const char *fg, const char *bo);
|
||||||
extern void loadfont(Display *dpy, Fnt *font, const char *fontstr);
|
extern void loadfont(Display *dpy, Fnt *font, const char *fontstr);
|
||||||
extern unsigned int textwidth_l(Fnt *font, char *text, unsigned int len);
|
extern unsigned int textnw(Fnt *font, char *text, unsigned int len);
|
||||||
extern unsigned int textwidth(Fnt *font, char *text);
|
extern unsigned int textw(Fnt *font, char *text);
|
||||||
extern unsigned int labelheight(Fnt *font);
|
extern unsigned int texth(Fnt *font);
|
||||||
|
17
event.c
17
event.c
@ -37,13 +37,11 @@ void (*handler[LASTEvent]) (XEvent *) = {
|
|||||||
[UnmapNotify] = unmapnotify
|
[UnmapNotify] = unmapnotify
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned int
|
void
|
||||||
discard_events(long even_mask)
|
discard_events(long even_mask)
|
||||||
{
|
{
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
unsigned int n = 0;
|
while(XCheckMaskEvent(dpy, even_mask, &ev));
|
||||||
while(XCheckMaskEvent(dpy, even_mask, &ev)) n++;
|
|
||||||
return n;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -53,6 +51,7 @@ buttonpress(XEvent *e)
|
|||||||
Client *c;
|
Client *c;
|
||||||
|
|
||||||
if((c = getclient(ev->window))) {
|
if((c = getclient(ev->window))) {
|
||||||
|
raise(c);
|
||||||
switch(ev->button) {
|
switch(ev->button) {
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -60,7 +59,7 @@ buttonpress(XEvent *e)
|
|||||||
mmove(c);
|
mmove(c);
|
||||||
break;
|
break;
|
||||||
case Button2:
|
case Button2:
|
||||||
XLowerWindow(dpy, c->win);
|
lower(c);
|
||||||
break;
|
break;
|
||||||
case Button3:
|
case Button3:
|
||||||
mresize(c);
|
mresize(c);
|
||||||
@ -122,10 +121,8 @@ enternotify(XEvent *e)
|
|||||||
|
|
||||||
if((c = getclient(ev->window)))
|
if((c = getclient(ev->window)))
|
||||||
focus(c);
|
focus(c);
|
||||||
else if(ev->window == root) {
|
else if(ev->window == root)
|
||||||
sel_screen = True;
|
sel_screen = True;
|
||||||
/*draw_frames();*/
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -133,10 +130,8 @@ leavenotify(XEvent *e)
|
|||||||
{
|
{
|
||||||
XCrossingEvent *ev = &e->xcrossing;
|
XCrossingEvent *ev = &e->xcrossing;
|
||||||
|
|
||||||
if((ev->window == root) && !ev->same_screen) {
|
if((ev->window == root) && !ev->same_screen)
|
||||||
sel_screen = True;
|
sel_screen = True;
|
||||||
/*draw_frames();*/
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
81
font.c
81
font.c
@ -1,81 +0,0 @@
|
|||||||
/*
|
|
||||||
* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
|
||||||
* See LICENSE file for license details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <locale.h>
|
|
||||||
|
|
||||||
unsigned int
|
|
||||||
textwidth_l(BlitzFont *font, char *text, unsigned int len)
|
|
||||||
{
|
|
||||||
if(font->set) {
|
|
||||||
XRectangle r;
|
|
||||||
XmbTextExtents(font->set, text, len, nil, &r);
|
|
||||||
return r.width;
|
|
||||||
}
|
|
||||||
return XTextWidth(font->xfont, text, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int
|
|
||||||
textwidth(BlitzFont *font, char *text)
|
|
||||||
{
|
|
||||||
return blitz_textwidth_l(font, text, strlen(text));
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
loadfont(Blitz *blitz, BlitzFont *font)
|
|
||||||
{
|
|
||||||
char *fontname = font->fontstr;
|
|
||||||
char **missing = nil, *def = "?";
|
|
||||||
int n;
|
|
||||||
|
|
||||||
setlocale(LC_ALL, "");
|
|
||||||
if(font->set)
|
|
||||||
XFreeFontSet(blitz->dpy, font->set);
|
|
||||||
font->set = XCreateFontSet(blitz->dpy, fontname, &missing, &n, &def);
|
|
||||||
if(missing) {
|
|
||||||
while(n--)
|
|
||||||
fprintf(stderr, "missing fontset: %s\n", missing[n]);
|
|
||||||
XFreeStringList(missing);
|
|
||||||
if(font->set) {
|
|
||||||
XFreeFontSet(blitz->dpy, font->set);
|
|
||||||
font->set = nil;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(font->set) {
|
|
||||||
XFontSetExtents *font_extents;
|
|
||||||
XFontStruct **xfonts;
|
|
||||||
char **font_names;
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
font->ascent = font->descent = 0;
|
|
||||||
font_extents = XExtentsOfFontSet(font->set);
|
|
||||||
n = XFontsOfFontSet(font->set, &xfonts, &font_names);
|
|
||||||
for(i = 0, font->ascent = 0, font->descent = 0; i < n; i++) {
|
|
||||||
if(font->ascent < (*xfonts)->ascent)
|
|
||||||
font->ascent = (*xfonts)->ascent;
|
|
||||||
if(font->descent < (*xfonts)->descent)
|
|
||||||
font->descent = (*xfonts)->descent;
|
|
||||||
xfonts++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(font->xfont)
|
|
||||||
XFreeFont(blitz->dpy, font->xfont);
|
|
||||||
font->xfont = nil;
|
|
||||||
font->xfont = XLoadQueryFont(blitz->dpy, fontname);
|
|
||||||
if (!font->xfont) {
|
|
||||||
fontname = "fixed";
|
|
||||||
font->xfont = XLoadQueryFont(blitz->dpy, fontname);
|
|
||||||
}
|
|
||||||
if (!font->xfont) {
|
|
||||||
fprintf(stderr, "%s", "error, cannot load 'fixed' font\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
font->ascent = font->xfont->ascent;
|
|
||||||
font->descent = font->xfont->descent;
|
|
||||||
}
|
|
||||||
}
|
|
97
menu.c
97
menu.c
@ -31,7 +31,6 @@ struct Item {
|
|||||||
static Display *dpy;
|
static Display *dpy;
|
||||||
static Window root;
|
static Window root;
|
||||||
static Window win;
|
static Window win;
|
||||||
static XRectangle rect;
|
|
||||||
static Bool done = False;
|
static Bool done = False;
|
||||||
|
|
||||||
static Item *allitem = NULL; /* first of all items */
|
static Item *allitem = NULL; /* first of all items */
|
||||||
@ -41,14 +40,14 @@ static Item *nextoff = NULL;
|
|||||||
static Item *prevoff = NULL;
|
static Item *prevoff = NULL;
|
||||||
static Item *curroff = NULL;
|
static Item *curroff = NULL;
|
||||||
|
|
||||||
static int screen;
|
static int screen, mx, my, mw, mh;
|
||||||
static char *title = NULL;
|
static char *title = NULL;
|
||||||
static char text[4096];
|
static char text[4096];
|
||||||
static int ret = 0;
|
static int ret = 0;
|
||||||
static int nitem = 0;
|
static int nitem = 0;
|
||||||
static unsigned int cmdw = 0;
|
static unsigned int cmdw = 0;
|
||||||
static unsigned int twidth = 0;
|
static unsigned int tw = 0;
|
||||||
static unsigned int cwidth = 0;
|
static unsigned int cw = 0;
|
||||||
static const int seek = 30; /* 30px */
|
static const int seek = 30; /* 30px */
|
||||||
|
|
||||||
static Brush brush = {0};
|
static Brush brush = {0};
|
||||||
@ -74,21 +73,21 @@ update_offsets()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
for(nextoff = curroff; nextoff; nextoff=nextoff->right) {
|
for(nextoff = curroff; nextoff; nextoff=nextoff->right) {
|
||||||
tw = textwidth(&brush.font, nextoff->text);
|
tw = textw(&brush.font, nextoff->text);
|
||||||
if(tw > rect.width / 3)
|
if(tw > mw / 3)
|
||||||
tw = rect.width / 3;
|
tw = mw / 3;
|
||||||
w += tw + brush.font.height;
|
w += tw + brush.font.height;
|
||||||
if(w > rect.width)
|
if(w > mw)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
w = cmdw + 2 * seek;
|
w = cmdw + 2 * seek;
|
||||||
for(prevoff = curroff; prevoff && prevoff->left; prevoff=prevoff->left) {
|
for(prevoff = curroff; prevoff && prevoff->left; prevoff=prevoff->left) {
|
||||||
tw = textwidth(&brush.font, prevoff->left->text);
|
tw = textw(&brush.font, prevoff->left->text);
|
||||||
if(tw > rect.width / 3)
|
if(tw > mw / 3)
|
||||||
tw = rect.width / 3;
|
tw = mw / 3;
|
||||||
w += tw + brush.font.height;
|
w += tw + brush.font.height;
|
||||||
if(w > rect.width)
|
if(w > mw)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -103,9 +102,9 @@ update_items(char *pattern)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if(!title || *pattern)
|
if(!title || *pattern)
|
||||||
cmdw = cwidth;
|
cmdw = cw;
|
||||||
else
|
else
|
||||||
cmdw = twidth;
|
cmdw = tw;
|
||||||
|
|
||||||
item = j = NULL;
|
item = j = NULL;
|
||||||
nitem = 0;
|
nitem = 0;
|
||||||
@ -143,42 +142,40 @@ update_items(char *pattern)
|
|||||||
static void
|
static void
|
||||||
draw_menu()
|
draw_menu()
|
||||||
{
|
{
|
||||||
unsigned int offx = 0;
|
|
||||||
Item *i;
|
Item *i;
|
||||||
|
|
||||||
brush.rect = rect;
|
brush.x = 0;
|
||||||
brush.rect.x = 0;
|
brush.y = 0;
|
||||||
brush.rect.y = 0;
|
brush.w = mw;
|
||||||
|
brush.h = mh;
|
||||||
draw(dpy, &brush, False, 0);
|
draw(dpy, &brush, False, 0);
|
||||||
|
|
||||||
/* print command */
|
/* print command */
|
||||||
if(!title || text[0]) {
|
if(!title || text[0]) {
|
||||||
cmdw = cwidth;
|
cmdw = cw;
|
||||||
if(cmdw && item)
|
if(cmdw && item)
|
||||||
brush.rect.width = cmdw;
|
brush.w = cmdw;
|
||||||
draw(dpy, &brush, False, text);
|
draw(dpy, &brush, False, text);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cmdw = twidth;
|
cmdw = tw;
|
||||||
brush.rect.width = cmdw;
|
brush.w = cmdw;
|
||||||
draw(dpy, &brush, False, title);
|
draw(dpy, &brush, False, title);
|
||||||
}
|
}
|
||||||
offx += brush.rect.width;
|
brush.x += brush.w;
|
||||||
|
|
||||||
if(curroff) {
|
if(curroff) {
|
||||||
brush.rect.x = offx;
|
brush.w = seek;
|
||||||
brush.rect.width = seek;
|
|
||||||
offx += brush.rect.width;
|
|
||||||
draw(dpy, &brush, False, (curroff && curroff->left) ? "<" : 0);
|
draw(dpy, &brush, False, (curroff && curroff->left) ? "<" : 0);
|
||||||
|
brush.x += brush.w;
|
||||||
|
|
||||||
/* determine maximum items */
|
/* determine maximum items */
|
||||||
for(i = curroff; i != nextoff; i=i->right) {
|
for(i = curroff; i != nextoff; i=i->right) {
|
||||||
brush.border = False;
|
brush.border = False;
|
||||||
brush.rect.x = offx;
|
brush.w = textw(&brush.font, i->text);
|
||||||
brush.rect.width = textwidth(&brush.font, i->text);
|
if(brush.w > mw / 3)
|
||||||
if(brush.rect.width > rect.width / 3)
|
brush.w = mw / 3;
|
||||||
brush.rect.width = rect.width / 3;
|
brush.w += brush.font.height;
|
||||||
brush.rect.width += brush.font.height;
|
|
||||||
if(sel == i) {
|
if(sel == i) {
|
||||||
swap((void **)&brush.fg, (void **)&brush.bg);
|
swap((void **)&brush.fg, (void **)&brush.bg);
|
||||||
draw(dpy, &brush, True, i->text);
|
draw(dpy, &brush, True, i->text);
|
||||||
@ -186,15 +183,14 @@ draw_menu()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
draw(dpy, &brush, False, i->text);
|
draw(dpy, &brush, False, i->text);
|
||||||
offx += brush.rect.width;
|
brush.x += brush.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
brush.rect.x = rect.width - seek;
|
brush.x = mw - seek;
|
||||||
brush.rect.width = seek;
|
brush.w = seek;
|
||||||
draw(dpy, &brush, False, nextoff ? ">" : 0);
|
draw(dpy, &brush, False, nextoff ? ">" : 0);
|
||||||
}
|
}
|
||||||
XCopyArea(dpy, brush.drawable, win, brush.gc, 0, 0, rect.width,
|
XCopyArea(dpy, brush.drawable, win, brush.gc, 0, 0, mw, mh, 0, 0);
|
||||||
rect.height, 0, 0);
|
|
||||||
XFlush(dpy);
|
XFlush(dpy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,36 +395,35 @@ main(int argc, char *argv[])
|
|||||||
wa.background_pixmap = ParentRelative;
|
wa.background_pixmap = ParentRelative;
|
||||||
wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask;
|
wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask;
|
||||||
|
|
||||||
rect.width = DisplayWidth(dpy, screen);
|
mx = my = 0;
|
||||||
rect.height = labelheight(&brush.font);
|
mw = DisplayWidth(dpy, screen);
|
||||||
rect.y = DisplayHeight(dpy, screen) - rect.height;
|
mh = texth(&brush.font);
|
||||||
rect.x = 0;
|
|
||||||
|
|
||||||
win = XCreateWindow(dpy, root, rect.x, rect.y,
|
win = XCreateWindow(dpy, root, mx, my, mw, mh, 0,
|
||||||
rect.width, rect.height, 0, DefaultDepth(dpy, screen),
|
DefaultDepth(dpy, screen), CopyFromParent,
|
||||||
CopyFromParent, DefaultVisual(dpy, screen),
|
DefaultVisual(dpy, screen),
|
||||||
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
|
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
|
||||||
XDefineCursor(dpy, win, XCreateFontCursor(dpy, XC_xterm));
|
XDefineCursor(dpy, win, XCreateFontCursor(dpy, XC_xterm));
|
||||||
XFlush(dpy);
|
XFlush(dpy);
|
||||||
|
|
||||||
/* pixmap */
|
/* pixmap */
|
||||||
brush.gc = XCreateGC(dpy, root, 0, 0);
|
brush.gc = XCreateGC(dpy, root, 0, 0);
|
||||||
brush.drawable = XCreatePixmap(dpy, win, rect.width, rect.height,
|
brush.drawable = XCreatePixmap(dpy, win, mw, mh,
|
||||||
DefaultDepth(dpy, screen));
|
DefaultDepth(dpy, screen));
|
||||||
XFlush(dpy);
|
XFlush(dpy);
|
||||||
|
|
||||||
if(maxname)
|
if(maxname)
|
||||||
cwidth = textwidth(&brush.font, maxname) + brush.font.height;
|
cw = textw(&brush.font, maxname) + brush.font.height;
|
||||||
if(cwidth > rect.width / 3)
|
if(cw > mw / 3)
|
||||||
cwidth = rect.width / 3;
|
cw = mw / 3;
|
||||||
|
|
||||||
if(title) {
|
if(title) {
|
||||||
twidth = textwidth(&brush.font, title) + brush.font.height;
|
tw = textw(&brush.font, title) + brush.font.height;
|
||||||
if(twidth > rect.width / 3)
|
if(tw > mw / 3)
|
||||||
twidth = rect.width / 3;
|
tw = mw / 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdw = title ? twidth : cwidth;
|
cmdw = title ? tw : cw;
|
||||||
|
|
||||||
text[0] = 0;
|
text[0] = 0;
|
||||||
update_items(text);
|
update_items(text);
|
||||||
|
20
mouse.c
20
mouse.c
@ -45,21 +45,21 @@ mresize(Client *c)
|
|||||||
if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
|
if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
|
||||||
None, cursor[CurResize], CurrentTime) != GrabSuccess)
|
None, cursor[CurResize], CurrentTime) != GrabSuccess)
|
||||||
return;
|
return;
|
||||||
XGrabServer(dpy);
|
|
||||||
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
|
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
|
||||||
for(;;) {
|
for(;;) {
|
||||||
XMaskEvent(dpy, MouseMask, &ev);
|
XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
|
||||||
switch(ev.type) {
|
switch(ev.type) {
|
||||||
default: break;
|
default: break;
|
||||||
|
case Expose:
|
||||||
|
handler[Expose](&ev);
|
||||||
|
break;
|
||||||
case MotionNotify:
|
case MotionNotify:
|
||||||
XUngrabServer(dpy);
|
XFlush(dpy);
|
||||||
mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y);
|
mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y);
|
||||||
XResizeWindow(dpy, c->win, c->w, c->h);
|
XResizeWindow(dpy, c->win, c->w, c->h);
|
||||||
XGrabServer(dpy);
|
|
||||||
break;
|
break;
|
||||||
case ButtonRelease:
|
case ButtonRelease:
|
||||||
resize(c);
|
resize(c);
|
||||||
XUngrabServer(dpy);
|
|
||||||
XUngrabPointer(dpy, CurrentTime);
|
XUngrabPointer(dpy, CurrentTime);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -80,21 +80,21 @@ mmove(Client *c)
|
|||||||
None, cursor[CurMove], CurrentTime) != GrabSuccess)
|
None, cursor[CurMove], CurrentTime) != GrabSuccess)
|
||||||
return;
|
return;
|
||||||
XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
|
XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
|
||||||
XGrabServer(dpy);
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
XMaskEvent(dpy, MouseMask, &ev);
|
XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
|
||||||
switch (ev.type) {
|
switch (ev.type) {
|
||||||
default: break;
|
default: break;
|
||||||
|
case Expose:
|
||||||
|
handler[Expose](&ev);
|
||||||
|
break;
|
||||||
case MotionNotify:
|
case MotionNotify:
|
||||||
XUngrabServer(dpy);
|
XFlush(dpy);
|
||||||
c->x = old_cx + (ev.xmotion.x - x1);
|
c->x = old_cx + (ev.xmotion.x - x1);
|
||||||
c->y = old_cy + (ev.xmotion.y - y1);
|
c->y = old_cy + (ev.xmotion.y - y1);
|
||||||
XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
|
XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
|
||||||
XGrabServer(dpy);
|
|
||||||
break;
|
break;
|
||||||
case ButtonRelease:
|
case ButtonRelease:
|
||||||
resize(c);
|
resize(c);
|
||||||
XUngrabServer(dpy);
|
|
||||||
XUngrabPointer(dpy, CurrentTime);
|
XUngrabPointer(dpy, CurrentTime);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
23
wm.c
23
wm.c
@ -23,12 +23,11 @@ Display *dpy;
|
|||||||
Window root, barwin;
|
Window root, barwin;
|
||||||
Atom wm_atom[WMLast], net_atom[NetLast];
|
Atom wm_atom[WMLast], net_atom[NetLast];
|
||||||
Cursor cursor[CurLast];
|
Cursor cursor[CurLast];
|
||||||
XRectangle rect, barrect;
|
|
||||||
Bool running = True;
|
Bool running = True;
|
||||||
Bool sel_screen;
|
Bool sel_screen;
|
||||||
|
|
||||||
char statustext[1024], tag[256];
|
char statustext[1024], tag[256];
|
||||||
int screen;
|
int screen, sx, sy, sw, sh, bx, by, bw, bh;
|
||||||
|
|
||||||
Brush brush = {0};
|
Brush brush = {0};
|
||||||
Client *clients = NULL;
|
Client *clients = NULL;
|
||||||
@ -39,7 +38,7 @@ static const char version[] = "gridwm - " VERSION ", (C)opyright MMVI Anselm R.
|
|||||||
static int (*x_error_handler) (Display *, XErrorEvent *);
|
static int (*x_error_handler) (Display *, XErrorEvent *);
|
||||||
|
|
||||||
static const char *status[] = {
|
static const char *status[] = {
|
||||||
"sh", "-c", "echo -n `date '+%Y/%m/%d %H:%M'`"
|
"sh", "-c", "echo -n `date '+%Y-%m-%d %H:%M'`"
|
||||||
" `uptime | sed 's/.*://; s/,//g'`"
|
" `uptime | sed 's/.*://; s/,//g'`"
|
||||||
" `acpi | awk '{print $4}' | sed 's/,//'`", 0
|
" `acpi | awk '{print $4}' | sed 's/,//'`", 0
|
||||||
};
|
};
|
||||||
@ -220,9 +219,9 @@ main(int argc, char *argv[])
|
|||||||
if(other_wm_running)
|
if(other_wm_running)
|
||||||
error("gridwm: another window manager is already running\n");
|
error("gridwm: another window manager is already running\n");
|
||||||
|
|
||||||
rect.x = rect.y = 0;
|
sx = sy = 0;
|
||||||
rect.width = DisplayWidth(dpy, screen);
|
sw = DisplayWidth(dpy, screen);
|
||||||
rect.height = DisplayHeight(dpy, screen);
|
sh = DisplayHeight(dpy, screen);
|
||||||
sel_screen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
|
sel_screen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
|
||||||
|
|
||||||
XSetErrorHandler(0);
|
XSetErrorHandler(0);
|
||||||
@ -253,18 +252,16 @@ main(int argc, char *argv[])
|
|||||||
wa.background_pixmap = ParentRelative;
|
wa.background_pixmap = ParentRelative;
|
||||||
wa.event_mask = ExposureMask;
|
wa.event_mask = ExposureMask;
|
||||||
|
|
||||||
barrect = rect;
|
bx = by = 0;
|
||||||
barrect.height = labelheight(&brush.font);
|
bw = sw;
|
||||||
barrect.y = rect.height - barrect.height;
|
bh = texth(&brush.font);
|
||||||
barwin = XCreateWindow(dpy, root, barrect.x, barrect.y,
|
barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, screen),
|
||||||
barrect.width, barrect.height, 0, DefaultDepth(dpy, screen),
|
|
||||||
CopyFromParent, DefaultVisual(dpy, screen),
|
CopyFromParent, DefaultVisual(dpy, screen),
|
||||||
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
|
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
|
||||||
XDefineCursor(dpy, barwin, cursor[CurNormal]);
|
XDefineCursor(dpy, barwin, cursor[CurNormal]);
|
||||||
XMapRaised(dpy, barwin);
|
XMapRaised(dpy, barwin);
|
||||||
|
|
||||||
brush.drawable = XCreatePixmap(dpy, root, rect.width, barrect.height,
|
brush.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
|
||||||
DefaultDepth(dpy, screen));
|
|
||||||
brush.gc = XCreateGC(dpy, root, 0, 0);
|
brush.gc = XCreateGC(dpy, root, 0, 0);
|
||||||
|
|
||||||
pipe_spawn(statustext, sizeof(statustext), dpy, (char **)status);
|
pipe_spawn(statustext, sizeof(statustext), dpy, (char **)status);
|
||||||
|
7
wm.h
7
wm.h
@ -46,11 +46,10 @@ extern Display *dpy;
|
|||||||
extern Window root, barwin;
|
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 XRectangle rect, barrect;
|
|
||||||
extern Bool running, sel_screen, grid;
|
extern Bool running, sel_screen, grid;
|
||||||
extern void (*handler[LASTEvent]) (XEvent *);
|
extern void (*handler[LASTEvent]) (XEvent *);
|
||||||
|
|
||||||
extern int screen;
|
extern int screen, sx, sy, sw, sh, bx, by, bw, bh;
|
||||||
extern char statustext[1024], tag[256];
|
extern char statustext[1024], tag[256];
|
||||||
|
|
||||||
extern Brush brush;
|
extern Brush brush;
|
||||||
@ -75,9 +74,11 @@ extern void draw_client(Client *c);
|
|||||||
extern void resize(Client *c);
|
extern void resize(Client *c);
|
||||||
extern void update_size(Client *c);
|
extern void update_size(Client *c);
|
||||||
extern Client *gettitle(Window w);
|
extern Client *gettitle(Window w);
|
||||||
|
extern void raise(Client *c);
|
||||||
|
extern void lower(Client *c);
|
||||||
|
|
||||||
/* event.c */
|
/* event.c */
|
||||||
extern unsigned int discard_events(long even_mask);
|
extern void discard_events(long even_mask);
|
||||||
|
|
||||||
/* key.c */
|
/* key.c */
|
||||||
extern void update_keys();
|
extern void update_keys();
|
||||||
|
Loading…
Reference in New Issue
Block a user