This commit is contained in:
exkc 2022-07-20 17:11:33 +08:00
parent 689e5c2d64
commit 2e1a1d51cf
13 changed files with 13 additions and 234 deletions

View File

@ -3,7 +3,7 @@
include config.mk
SRC = client.c dev.c draw.c event.c main.c util.c
SRC = client.c event.c main.c util.c
OBJ = ${SRC:.c=.o}
MAN1 = dumbwm.1
BIN = dumbwm

BIN
bar.o

Binary file not shown.

View File

@ -52,9 +52,9 @@ max(Arg *arg)
if(!sel)
return;
sel->x = sx;
sel->y = sy + bh;
sel->y = sy ;
sel->w = sw - 2 * sel->border;
sel->h = sh - 2 * sel->border - bh;
sel->h = sh - 2 * sel->border;
craise(sel);
resize(sel, False);
}
@ -107,9 +107,9 @@ tiling(Arg *arg)
n++;
if(n > 1)
h = (sh - bh) / (n - 1);
h = (sh ) / (n - 1);
else
h = sh - bh;
h = sh;
for(i = 0, c = clients; c; c = c->next) {
if(c->floating) {
@ -119,19 +119,19 @@ tiling(Arg *arg)
}
if(n == 1) {
c->x = sx;
c->y = sy + bh;
c->y = sy ;
c->w = sw - 2 * c->border;
c->h = sh - 2 * c->border - bh;
c->h = sh - 2 * c->border ;
}
else if(i == 0) {
c->x = sx;
c->y = sy + bh;
c->y = sy ;
c->w = mw - 2 * c->border;
c->h = sh - 2 * c->border - bh;
c->h = sh - 2 * c->border ;
}
else {
c->x = sx + mw;
c->y = sy + (i - 1) * h + bh;
c->y = sy + (i - 1) * h ;
c->w = w - 2 * c->border;
c->h = h - 2 * c->border;
}
@ -289,12 +289,9 @@ 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 = bh;
c->border = 1;
c->border = 0;
c->proto = win_proto(c->win);
update_size(c);
XSelectInput(dpy, c->win,

BIN
client.o

Binary file not shown.

123
dev.c
View File

@ -1,123 +0,0 @@
/*
* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include "dumbwm.h"
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <X11/keysym.h>
/********** CUSTOMIZE **********/
static Key key[] = {
/* modifier key function arguments */
{ Mod1Mask|ShiftMask, XK_q, quit, { 0 } },
};
/********** CUSTOMIZE **********/
void
update_keys(void)
{
static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
unsigned int i;
KeyCode code;
for(i = 0; i < len; i++) {
code = XKeysymToKeycode(dpy, key[i].keysym);
XUngrabKey(dpy, code, key[i].mod, root);
XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync);
}
}
void
keypress(XEvent *e)
{
XKeyEvent *ev = &e->xkey;
static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
unsigned int i;
KeySym keysym;
keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
for(i = 0; i < len; i++)
if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
if(key[i].func)
key[i].func(&key[i].arg);
return;
}
}
#define ButtonMask (ButtonPressMask | ButtonReleaseMask)
#define MouseMask (ButtonMask | PointerMotionMask)
void
mresize(Client *c)
{
XEvent ev;
int ocx, ocy;
ocx = c->x;
ocy = c->y;
if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
None, cursor[CurResize], CurrentTime) != GrabSuccess)
return;
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
for(;;) {
XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
switch(ev.type) {
default: break;
case Expose:
handler[Expose](&ev);
break;
case MotionNotify:
XFlush(dpy);
c->w = abs(ocx - ev.xmotion.x);
c->h = abs(ocy - ev.xmotion.y);
c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
resize(c, True);
break;
case ButtonRelease:
XUngrabPointer(dpy, CurrentTime);
return;
}
}
}
void
mmove(Client *c)
{
XEvent ev;
int x1, y1, ocx, ocy, di;
unsigned int dui;
Window dummy;
ocx = c->x;
ocy = c->y;
if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
None, cursor[CurMove], CurrentTime) != GrabSuccess)
return;
XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
for(;;) {
XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
switch (ev.type) {
default: break;
case Expose:
handler[Expose](&ev);
break;
case MotionNotify:
XFlush(dpy);
c->x = ocx + (ev.xmotion.x - x1);
c->y = ocy + (ev.xmotion.y - y1);
resize(c, False);
break;
case ButtonRelease:
XUngrabPointer(dpy, CurrentTime);
return;
}
}
}

BIN
dev.o

Binary file not shown.

41
draw.c
View File

@ -1,41 +0,0 @@
/*
* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include <stdio.h>
#include <string.h>
#include <X11/Xlocale.h>
#include "dumbwm.h"
static void
drawborder(void)
{
}
void
drawtext(const char *text, Bool invert, Bool border)
{
}
unsigned long
initcolor(const char *colstr)
{
}
unsigned int
textnw(char *text, unsigned int len)
{
}
unsigned int
textw(char *text)
{
}
void
initfont(const char *fontstr)
{
}

BIN
draw.o

Binary file not shown.

BIN
dumbwm Executable file

Binary file not shown.

37
event.c
View File

@ -7,7 +7,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>
#include "dumbwm.h"
@ -19,51 +18,21 @@ static void destroynotify(XEvent *e);
static void enternotify(XEvent *e);
static void leavenotify(XEvent *e);
static void expose(XEvent *e);
static void keymapnotify(XEvent *e);
static void maprequest(XEvent *e);
static void propertynotify(XEvent *e);
static void unmapnotify(XEvent *e);
void (*handler[LASTEvent]) (XEvent *) = {
[ButtonPress] = buttonpress,
[ConfigureRequest] = configurerequest,
[DestroyNotify] = destroynotify,
[EnterNotify] = enternotify,
[LeaveNotify] = leavenotify,
[Expose] = expose,
[KeyPress] = keypress,
[KeymapNotify] = keymapnotify,
[MapRequest] = maprequest,
[PropertyNotify] = propertynotify,
[UnmapNotify] = unmapnotify
};
static void
buttonpress(XEvent *e)
{
XButtonPressedEvent *ev = &e->xbutton;
Client *c;
if(barwin == ev->window)
barclick(ev);
else if((c = getclient(ev->window))) {
craise(c);
switch(ev->button) {
default:
break;
case Button1:
mmove(c);
break;
case Button2:
lower(c);
break;
case Button3:
mresize(c);
break;
}
}
}
static void
configurerequest(XEvent *e)
{
@ -143,12 +112,6 @@ expose(XEvent *e)
}
static void
keymapnotify(XEvent *e)
{
update_keys();
}
static void
maprequest(XEvent *e)
{

BIN
event.o

Binary file not shown.

21
main.c
View File

@ -23,17 +23,16 @@
/* X structs */
Display *dpy;
Window root, barwin;
Window root;
Atom wm_atom[WMLast], net_atom[NetLast];
Cursor cursor[CurLast];
Bool running = True;
Bool issel;
int tsel = Tdev; /* default tag */
int screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
int screen, sx, sy, sw, sh, mw;
char stext[1024];
DC dc = {0};
Client *clients = NULL;
Client *sel = NULL;
@ -233,13 +232,8 @@ main(int argc, char *argv[])
cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
update_keys();
/* style */
dc.bg = initcolor(BGCOLOR);
dc.fg = initcolor(FGCOLOR);
dc.border = initcolor(BORDERCOLOR);
initfont(FONT);
sx = sy = 0;
sw = DisplayWidth(dpy, screen);
@ -250,17 +244,6 @@ main(int argc, char *argv[])
wa.background_pixmap = ParentRelative;
wa.event_mask = ButtonPressMask | 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);
dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
dc.gc = XCreateGC(dpy, root, 0, 0);
issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);

BIN
main.o

Binary file not shown.