This commit is contained in:
exkc 2022-07-20 17:27:37 +08:00
parent 2e1a1d51cf
commit e5ef069c9b
8 changed files with 2 additions and 182 deletions

View File

@ -6,16 +6,12 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include "dumbwm.h"
void (*arrange)(Arg *) = tiling;
static Rule rule[] = {
{ "Firefox-bin", "Gecko", { [Twww] = "www" }, False },
};
static Client *
next(Client *c)
@ -24,28 +20,6 @@ next(Client *c)
return c;
}
void
zoom(Arg *arg)
{
Client **l, *c;
if(!sel)
return;
if(sel == next(clients) && sel->next) {
if((c = next(sel->next)))
sel = c;
}
for(l = &clients; *l && *l != sel; l = &(*l)->next);
*l = sel->next;
sel->next = clients; /* pop */
clients = sel;
arrange(NULL);
focus(sel);
}
void
max(Arg *arg)
{
@ -68,33 +42,6 @@ view(Arg *arg)
arrange(NULL);
}
void
tappend(Arg *arg)
{
if(!sel)
return;
arrange(NULL);
}
void
ttrunc(Arg *arg)
{
int i;
if(!sel)
return;
for(i = 0; i < TLast; i++)
tappend(arg);
}
static void
ban_client(Client *c)
{
XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
}
void
tiling(Arg *arg)
{
@ -182,39 +129,11 @@ ckill(Arg *arg)
{
if(!sel)
return;
if(sel->proto & WM_PROTOCOL_DELWIN)
send_message(sel->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
else
XKillClient(dpy, sel->win);
}
void
update_name(Client *c)
{
XTextProperty name;
int n;
char **list = NULL;
name.nitems = 0;
c->name[0] = 0;
XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
if(!name.nitems)
XGetWMName(dpy, c->win, &name);
if(!name.nitems)
return;
if(name.encoding == XA_STRING)
strncpy(c->name, (char *)name.value, sizeof(c->name));
else {
if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
&& n > 0 && *list)
{
strncpy(c->name, *list, sizeof(c->name));
XFreeStringList(list);
}
}
XFree(name.value);
}
void
update_size(Client *c)
{
@ -292,7 +211,6 @@ manage(Window w, XWindowAttributes *wa)
c->tw = c->w = wa->width;
c->h = wa->height;
c->border = 0;
c->proto = win_proto(c->win);
update_size(c);
XSelectInput(dpy, c->win,
StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
@ -301,7 +219,6 @@ manage(Window w, XWindowAttributes *wa)
twa.background_pixmap = ParentRelative;
twa.event_mask = ExposureMask;
update_name(c);
for(l = &clients; *l; l = &(*l)->next);
c->next = *l; /* *l == nil */

BIN
client.o

Binary file not shown.

View File

@ -14,7 +14,7 @@ VERSION = 0.1
LIBS = -L${PREFIX}/lib -L/usr/lib -lc -L${X11LIB} -lX11
# Linux/BSD
CFLAGS = -Os -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \
CFLAGS = -Os -I. -pedantic -Wall -Wno-deprecated-declarations -I${PREFIX}/include -I/usr/include -I${X11INC} \
-DVERSION=\"${VERSION}\"
LDFLAGS = ${LIBS}
#CFLAGS = -g -Wall -O2 -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \

BIN
dumbwm

Binary file not shown.

34
event.c
View File

@ -19,7 +19,6 @@ static void enternotify(XEvent *e);
static void leavenotify(XEvent *e);
static void expose(XEvent *e);
static void maprequest(XEvent *e);
static void propertynotify(XEvent *e);
static void unmapnotify(XEvent *e);
void (*handler[LASTEvent]) (XEvent *) = {
@ -29,7 +28,6 @@ void (*handler[LASTEvent]) (XEvent *) = {
[LeaveNotify] = leavenotify,
[Expose] = expose,
[MapRequest] = maprequest,
[PropertyNotify] = propertynotify,
[UnmapNotify] = unmapnotify
};
@ -131,38 +129,6 @@ maprequest(XEvent *e)
manage(ev->window, &wa);
}
static void
propertynotify(XEvent *e)
{
XPropertyEvent *ev = &e->xproperty;
Window trans;
Client *c;
if(ev->state == PropertyDelete)
return; /* ignore */
if((c = getclient(ev->window))) {
if(ev->atom == wm_atom[WMProtocols]) {
c->proto = win_proto(c->win);
return;
}
switch (ev->atom) {
default: break;
case XA_WM_TRANSIENT_FOR:
XGetTransientForHint(dpy, c->win, &trans);
if(!c->floating && (c->floating = (trans != 0)))
arrange(NULL);
break;
case XA_WM_NORMAL_HINTS:
update_size(c);
break;
}
if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
update_name(c);
}
}
}
static void
unmapnotify(XEvent *e)
{

BIN
event.o

Binary file not shown.

63
main.c
View File

@ -11,7 +11,6 @@
#include <unistd.h>
#include <X11/cursorfont.h>
#include <X11/Xatom.h>
#include <X11/Xproto.h>
#include "dumbwm.h"
@ -24,7 +23,6 @@
/* X structs */
Display *dpy;
Window root;
Atom wm_atom[WMLast], net_atom[NetLast];
Cursor cursor[CurLast];
Bool running = True;
Bool issel;
@ -66,60 +64,6 @@ scan_wins()
XFree(wins);
}
static int
win_property(Window w, Atom a, Atom t, long l, unsigned char **prop)
{
Atom real;
int format;
unsigned long res, extra;
int status;
status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format,
&res, &extra, prop);
if(status != Success || *prop == 0) {
return 0;
}
if(res == 0) {
free((void *) *prop);
}
return res;
}
int
win_proto(Window w)
{
unsigned char *protocols;
long res;
int protos = 0;
int i;
res = win_property(w, wm_atom[WMProtocols], XA_ATOM, 20L, &protocols);
if(res <= 0) {
return protos;
}
for(i = 0; i < res; i++) {
if(protocols[i] == wm_atom[WMDelete])
protos |= WM_PROTOCOL_DELWIN;
}
free((char *) protocols);
return protos;
}
void
send_message(Window w, Atom a, long value)
{
XEvent e;
e.type = ClientMessage;
e.xclient.window = w;
e.xclient.message_type = a;
e.xclient.format = 32;
e.xclient.data.l[0] = value;
e.xclient.data.l[1] = CurrentTime;
XSendEvent(dpy, w, False, NoEventMask, &e);
XFlush(dpy);
}
/*
* There's no way to check accesses to destroyed windows, thus
@ -219,13 +163,6 @@ main(int argc, char *argv[])
XSetErrorHandler(0);
x_error_handler = XSetErrorHandler(error_handler);
/* init atoms */
wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
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);

BIN
main.o

Binary file not shown.