aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/config/config.mk40
-rw-r--r--src/core/dwm.c4
-rw-r--r--src/core/dwm.h2
-rw-r--r--src/core/globals.h21
-rw-r--r--src/core/types.h158
-rw-r--r--src/drw/drw.c2
-rw-r--r--src/drw/drw.h1
-rw-r--r--src/transient/transient.c90
-rw-r--r--src/ui/bar.h13
-rw-r--r--src/ui/input.h13
-rw-r--r--src/ui/systray.h12
-rw-r--r--src/util/util.c4
-rw-r--r--src/util/util.h4
-rw-r--r--src/wm/client.h26
-rw-r--r--src/wm/layout.h12
-rw-r--r--src/wm/monitor.h15
-rw-r--r--src/x11/xevents.h25
-rw-r--r--src/x11/xutil.h21
18 files changed, 325 insertions, 138 deletions
diff --git a/src/config/config.mk b/src/config/config.mk
deleted file mode 100644
index f8dab1b..0000000
--- a/src/config/config.mk
+++ /dev/null
@@ -1,40 +0,0 @@
1# dwm version
2VERSION = 6.4
3
4# Customize below to fit your system
5
6# paths
7PREFIX = /usr/local
8MANPREFIX = ${PREFIX}/share/man
9
10X11INC = /usr/X11R6/include
11X11LIB = /usr/X11R6/lib
12
13# Xinerama, comment if you don't want it
14XINERAMALIBS = -lXinerama
15XINERAMAFLAGS = -DXINERAMA
16
17# freetype
18FREETYPELIBS = -lfontconfig -lXft
19FREETYPEINC = /usr/include/freetype2
20# OpenBSD (uncomment)
21#FREETYPEINC = ${X11INC}/freetype2
22#MANPREFIX = ${PREFIX}/man
23#KVMLIB = -lkvm
24
25# includes and libs
26INCS = -I${X11INC} -I${FREETYPEINC}
27LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lX11-xcb -lxcb -lxcb-res ${KVMLIB}
28
29# flags
30CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
31#CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
32CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Os ${INCS} ${CPPFLAGS}
33LDFLAGS = ${LIBS}
34
35# Solaris
36#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
37#LDFLAGS = ${LIBS}
38
39# compiler and linker
40CC = tcc
diff --git a/src/core/dwm.c b/src/core/dwm.c
index cd7fdb0..6d4cdcd 100644
--- a/src/core/dwm.c
+++ b/src/core/dwm.c
@@ -851,7 +851,7 @@ Atom getatomprop(Client *c, Atom prop)
851 return atom; 851 return atom;
852} 852}
853 853
854unsigned int getsystraywidth() 854unsigned int getsystraywidth(void)
855{ 855{
856 unsigned int w = 0; 856 unsigned int w = 0;
857 Client *i; 857 Client *i;
@@ -1970,7 +1970,7 @@ void updatebarpos(Monitor *m)
1970 m->by = -bh; 1970 m->by = -bh;
1971} 1971}
1972 1972
1973void updateclientlist() 1973void updateclientlist(void)
1974{ 1974{
1975 Client *c; 1975 Client *c;
1976 Monitor *m; 1976 Monitor *m;
diff --git a/src/core/dwm.h b/src/core/dwm.h
index 273645a..d3bdf5a 100644
--- a/src/core/dwm.h
+++ b/src/core/dwm.h
@@ -153,7 +153,7 @@ static void focusin(XEvent *e);
153static Atom getatomprop(Client *c, Atom prop); 153static Atom getatomprop(Client *c, Atom prop);
154static int getrootptr(int *x, int *y); 154static int getrootptr(int *x, int *y);
155static long getstate(Window w); 155static long getstate(Window w);
156static unsigned int getsystraywidth(); 156static unsigned int getsystraywidth(void);
157static int gettextprop(Window w, Atom atom, char *text, unsigned int size); 157static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
158static void grabbuttons(Client *c, int focused); 158static void grabbuttons(Client *c, int focused);
159static void grabkeys(void); 159static void grabkeys(void);
diff --git a/src/core/globals.h b/src/core/globals.h
new file mode 100644
index 0000000..4b800fe
--- /dev/null
+++ b/src/core/globals.h
@@ -0,0 +1,21 @@
1
2#pragma once
3
4#include "types.h"
5
6extern Display *dpy;
7extern Window root, wmcheckwin;
8
9extern Monitor *mons, *selmon;
10
11extern int screen;
12extern int sw, sh;
13extern int bh;
14extern int running;
15extern unsigned int numlockmask;
16
17extern Atom wmatom[WMLast];
18extern Atom netatom[NetLast];
19extern Atom xatom[XLast];
20
21extern Systray *systray;
diff --git a/src/core/types.h b/src/core/types.h
new file mode 100644
index 0000000..dc10fc0
--- /dev/null
+++ b/src/core/types.h
@@ -0,0 +1,158 @@
1
2#pragma once
3
4#include <X11/Xatom.h>
5#include <X11/Xlib.h>
6#include <sys/types.h>
7
8/* cursors */
9enum { CurNormal, CurResize, CurMove, CurLast };
10
11/* color schemes */
12enum { SchemeNorm, SchemeSel };
13
14/* EWMH atoms */
15enum {
16 NetSupported,
17 NetWMName,
18 NetWMState,
19 NetWMCheck,
20 NetSystemTray,
21 NetSystemTrayOP,
22 NetSystemTrayOrientation,
23 NetSystemTrayOrientationHorz,
24 NetWMFullscreen,
25 NetActiveWindow,
26 NetWMWindowType,
27 NetWMWindowTypeDialog,
28 NetClientList,
29 NetLast
30};
31
32/* XEmbed */
33enum { Manager, Xembed, XembedInfo, XLast };
34
35/* ICCCM */
36enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast };
37
38/* clicks */
39enum {
40 ClkTagBar,
41 ClkLtSymbol,
42 ClkStatusText,
43 ClkWinTitle,
44 ClkClientWin,
45 ClkRootWin,
46 ClkLast
47};
48
49/* generic argument */
50typedef union {
51 int i;
52 unsigned int ui;
53 float f;
54 const void *v;
55} Arg;
56
57/* input */
58typedef struct {
59 unsigned int click;
60 unsigned int mask;
61 unsigned int button;
62 void (*func)(const Arg *arg);
63 const Arg arg;
64} Button;
65
66typedef struct {
67 unsigned int mod;
68 KeySym keysym;
69 void (*func)(const Arg *);
70 const Arg arg;
71} Key;
72
73/* forward decls */
74typedef struct Client Client;
75typedef struct Monitor Monitor;
76
77/* layout */
78typedef struct {
79 const char *symbol;
80 void (*arrange)(Monitor *);
81} Layout;
82
83/* client */
84struct Client {
85 char name[256];
86
87 float mina, maxa;
88 int basew, baseh, incw, inch, maxw, maxh, minw, minh;
89 int hintsvalid;
90
91 int x, y, w, h;
92 int oldx, oldy, oldw, oldh;
93 int bw, oldbw;
94
95 unsigned int tags;
96 int isfixed, isfloating, isurgent, neverfocus;
97 int oldstate, isfullscreen;
98 int isterminal, noswallow;
99
100 pid_t pid;
101
102 Client *next;
103 Client *snext;
104 Client *swallowing;
105
106 Monitor *mon;
107 Window win;
108};
109
110/* monitor */
111struct Monitor {
112 char ltsymbol[16];
113
114 float mfact;
115 int nmaster;
116 int num;
117
118 int mx, my, mw, mh;
119 int wx, wy, ww, wh;
120 int by;
121
122 int gappih, gappiv;
123 int gappoh, gappov;
124
125 unsigned int seltags;
126 unsigned int sellt;
127 unsigned int tagset[2];
128
129 int showbar;
130 int topbar;
131
132 Client *clients;
133 Client *sel;
134 Client *stack;
135
136 Monitor *next;
137 Window barwin;
138
139 const Layout *lt[2];
140};
141
142/* rules */
143typedef struct {
144 const char *class;
145 const char *instance;
146 const char *title;
147 unsigned int tags;
148 int isfloating;
149 int isterminal;
150 int noswallow;
151 int monitor;
152} Rule;
153
154/* systray */
155typedef struct Systray {
156 Window win;
157 Client *icons;
158} Systray;
diff --git a/src/drw/drw.c b/src/drw/drw.c
index 05420c0..5e90c2c 100644
--- a/src/drw/drw.c
+++ b/src/drw/drw.c
@@ -111,7 +111,7 @@ static Fnt *xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern)
111 /* Using the pattern found at font->xfont->pattern does not 111 /* Using the pattern found at font->xfont->pattern does not
112 * yield the same substitution results as using the pattern 112 * yield the same substitution results as using the pattern
113 * returned by FcNameParse; using the latter results in the 113 * returned by FcNameParse; using the latter results in the
114 * desired fallback behaviour whereas the former just results in 114 * desired fallback behavior whereas the former just results in
115 * missing-character rectangles being drawn, at least with some 115 * missing-character rectangles being drawn, at least with some
116 * fonts. */ 116 * fonts. */
117 if (!(xfont = 117 if (!(xfont =
diff --git a/src/drw/drw.h b/src/drw/drw.h
index 88308ab..e1c91ae 100644
--- a/src/drw/drw.h
+++ b/src/drw/drw.h
@@ -1,5 +1,6 @@
1/* See LICENSE file for copyright and license details. */ 1/* See LICENSE file for copyright and license details. */
2 2
3#include <X11/Xft/Xft.h>
3typedef struct { 4typedef struct {
4 Cursor cursor; 5 Cursor cursor;
5} Cur; 6} Cur;
diff --git a/src/transient/transient.c b/src/transient/transient.c
deleted file mode 100644
index fed0f77..0000000
--- a/src/transient/transient.c
+++ /dev/null
@@ -1,90 +0,0 @@
1#include <X11/Xlib.h>
2#include <X11/Xutil.h>
3#include <stdlib.h>
4#include <unistd.h>
5
6#define FLOATING_WINDOW_WIDTH 400
7#define FLOATING_WINDOW_HEIGHT 400
8#define FLOATING_WINDOW_X_POS 100
9#define FLOATING_WINDOW_Y_POS 100
10
11#define TRANSIENT_WINDOW_WIDTH 100
12#define TRANSIENT_WINDOW_HEIGHT 100
13#define TRANSIENT_WINDOW_X_POS 50
14#define TRANSIENT_WINDOW_Y_POS 50
15
16#define SLEEP_TIME 5
17
18#define WINDOW_BORDER_WIDTH 0
19#define WINDOW_BORDER_COLOR 0
20#define WINDOW_BACKGROUND_COLOR 0
21
22/**
23 * @brief Function that creates and manages floating and transient window.
24 *
25 * This program opens an X display, creates a floating window with specific
26 * size and position, and then creates a transient (child) window after a
27 * specified delay. The transient window is always associated with the
28 * floating window, meaning it will behave as a child of the floating window.
29 * The program uses Xlib to interact with the X server, handle events, and
30 * manage window properties such as size, title, and position.
31 *
32 * The key steps are:
33 * 1. Create the floating window and set its size constraints.
34 * 2. After a delay (5 seconds), create the transient window and associate
35 * it with the floating window.
36 * 3. Display both windows on the screen.
37 * 4. Wait for and process X events in an infinite loop. This allows the
38 * windows to remain open and interact with the X server.
39 *
40 * @return int Exit status (always 0).
41 */
42int main(void)
43{
44 Display *display;
45 Window rootWindow, floatingWindow, transientWindow = None;
46 XSizeHints sizeHints;
47 XEvent event;
48
49 display = XOpenDisplay(NULL);
50 if (!display)
51 exit(1);
52
53 rootWindow = DefaultRootWindow(display);
54
55 floatingWindow = XCreateSimpleWindow(
56 display, rootWindow, FLOATING_WINDOW_X_POS, FLOATING_WINDOW_Y_POS,
57 FLOATING_WINDOW_WIDTH, FLOATING_WINDOW_HEIGHT, WINDOW_BORDER_WIDTH,
58 WINDOW_BORDER_COLOR, WINDOW_BACKGROUND_COLOR);
59
60 sizeHints.min_width = sizeHints.max_width = sizeHints.min_height =
61 sizeHints.max_height = FLOATING_WINDOW_WIDTH;
62 sizeHints.flags = PMinSize | PMaxSize;
63 XSetWMNormalHints(display, floatingWindow, &sizeHints);
64 XStoreName(display, floatingWindow, "floating");
65 XMapWindow(display, floatingWindow);
66 XSelectInput(display, floatingWindow, ExposureMask);
67
68 while (1) {
69 XNextEvent(display, &event);
70
71 if (transientWindow == None) {
72 sleep(SLEEP_TIME);
73
74 transientWindow = XCreateSimpleWindow(
75 display, rootWindow, TRANSIENT_WINDOW_X_POS,
76 TRANSIENT_WINDOW_Y_POS, TRANSIENT_WINDOW_WIDTH,
77 TRANSIENT_WINDOW_HEIGHT, WINDOW_BORDER_WIDTH,
78 WINDOW_BORDER_COLOR, WINDOW_BACKGROUND_COLOR);
79
80 XSetTransientForHint(display, transientWindow,
81 floatingWindow);
82 XStoreName(display, transientWindow, "transient");
83 XMapWindow(display, transientWindow);
84 XSelectInput(display, transientWindow, ExposureMask);
85 }
86 }
87
88 XCloseDisplay(display);
89 exit(0);
90}
diff --git a/src/ui/bar.h b/src/ui/bar.h
new file mode 100644
index 0000000..79e4912
--- /dev/null
+++ b/src/ui/bar.h
@@ -0,0 +1,13 @@
1
2#pragma once
3
4#include "../core/types.h"
5
6void drawbar(Monitor *m);
7void drawbars(void);
8void updatebars(void);
9void updatestatus(void);
10unsigned int getsystraywidth(void);
11
12extern char stext[256];
13extern int lrpad;
diff --git a/src/ui/input.h b/src/ui/input.h
new file mode 100644
index 0000000..54e3c58
--- /dev/null
+++ b/src/ui/input.h
@@ -0,0 +1,13 @@
1
2#pragma once
3
4#include "../core/types.h"
5
6void grabkeys(void);
7void grabbuttons(Client *c, int focused);
8
9void keypress(XEvent *e);
10void buttonpress(XEvent *e);
11
12void movemouse(const Arg *arg);
13void resizemouse(const Arg *arg);
diff --git a/src/ui/systray.h b/src/ui/systray.h
new file mode 100644
index 0000000..ad78f58
--- /dev/null
+++ b/src/ui/systray.h
@@ -0,0 +1,12 @@
1
2#pragma once
3
4#include "../core/types.h"
5
6void updatesystray(void);
7void removesystrayicon(Client *i);
8void updatesystrayicongeom(Client *i, int w, int h);
9void updatesystrayiconstate(Client *i, XPropertyEvent *ev);
10
11Client *wintosystrayicon(Window w);
12Monitor *systraytomon(Monitor *m);
diff --git a/src/util/util.c b/src/util/util.c
index 61c864c..7938f0f 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -54,11 +54,11 @@ void die(const char *format_string, ...)
54 * int *array = ecalloc(10, sizeof(int)); // Allocate memory for an array of 54 * int *array = ecalloc(10, sizeof(int)); // Allocate memory for an array of
55 * 10 integers. 55 * 10 integers.
56 */ 56 */
57void *ecalloc(size_t num_elements, size_t element_size) 57void *ecalloc(const size_t num_elements, const size_t element_size)
58{ 58{
59 void *allocated_memory; 59 void *allocated_memory;
60 60
61 if (!(allocated_memory = calloc(num_elements, element_size))) 61 if (!((allocated_memory = calloc(num_elements, element_size))))
62 die("calloc:"); 62 die("calloc:");
63 63
64 return allocated_memory; 64 return allocated_memory;
diff --git a/src/util/util.h b/src/util/util.h
index 6ef3c86..2c2f773 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -35,7 +35,7 @@
35 * Usage: 35 * Usage:
36 * die("Error occurred in function %s", __func__); 36 * die("Error occurred in function %s", __func__);
37 */ 37 */
38void die(const char *fmt, ...); 38void die(const char *format_string, ...);
39 39
40/* 40/*
41 * ecalloc() 41 * ecalloc()
@@ -56,4 +56,4 @@ void die(const char *fmt, ...);
56 * int *arr = ecalloc(10, sizeof(int)); // Allocate memory for an array of 10 56 * int *arr = ecalloc(10, sizeof(int)); // Allocate memory for an array of 10
57 * integers. 57 * integers.
58 */ 58 */
59void *ecalloc(size_t nmemb, size_t size); 59void *ecalloc(size_t num_elements, size_t element_size);
diff --git a/src/wm/client.h b/src/wm/client.h
new file mode 100644
index 0000000..8a2a05e
--- /dev/null
+++ b/src/wm/client.h
@@ -0,0 +1,26 @@
1
2#pragma once
3
4#include "../core/types.h"
5
6void manage(Window w, XWindowAttributes *wa);
7void unmanage(Client *c, int destroyed);
8
9void attach(Client *c);
10void detach(Client *c);
11void attachstack(Client *c);
12void detachstack(Client *c);
13
14void focus(Client *c);
15void unfocus(Client *c, int setfocus);
16
17void resize(Client *c, int x, int y, int w, int h, int interact);
18void resizeclient(Client *c, int x, int y, int w, int h);
19
20Client *nexttiled(Client *c);
21Client *wintoclient(Window w);
22
23/* swallow (optional) */
24Client *swallowingclient(Window w);
25Client *termforwin(const Client *c);
26pid_t winpid(Window w);
diff --git a/src/wm/layout.h b/src/wm/layout.h
new file mode 100644
index 0000000..5deab64
--- /dev/null
+++ b/src/wm/layout.h
@@ -0,0 +1,12 @@
1
2#pragma once
3
4#include "../core/types.h"
5
6void arrange(Monitor *m);
7void arrangemon(Monitor *m);
8void tile(Monitor *m);
9void restack(Monitor *m);
10void showhide(Client *c);
11void zoom(const Arg *arg);
12void setlayout(const Arg *arg);
diff --git a/src/wm/monitor.h b/src/wm/monitor.h
new file mode 100644
index 0000000..e09935e
--- /dev/null
+++ b/src/wm/monitor.h
@@ -0,0 +1,15 @@
1
2#pragma once
3
4#include "../core/types.h"
5
6Monitor *createmon(void);
7void cleanupmon(Monitor *mon);
8
9Monitor *recttomon(int x, int y, int w, int h);
10Monitor *wintomon(Window w);
11void sendmon(Client *c, Monitor *m);
12
13int updategeom(void);
14void updatebarpos(Monitor *m);
15void resizebarwin(Monitor *m);
diff --git a/src/x11/xevents.h b/src/x11/xevents.h
new file mode 100644
index 0000000..98129bb
--- /dev/null
+++ b/src/x11/xevents.h
@@ -0,0 +1,25 @@
1
2#pragma once
3
4#include <X11/Xlib.h>
5
6void run(void);
7void scan(void);
8
9void buttonpress(XEvent *e);
10void keypress(XEvent *e);
11void maprequest(XEvent *e);
12void configurerequest(XEvent *e);
13void configurenotify(XEvent *e);
14void destroynotify(XEvent *e);
15void unmapnotify(XEvent *e);
16void clientmessage(XEvent *e);
17void propertynotify(XEvent *e);
18void resizerequest(XEvent *e);
19void mappingnotify(XEvent *e);
20void motionnotify(XEvent *e);
21void enternotify(XEvent *e);
22void focusin(XEvent *e);
23void expose(XEvent *e);
24
25extern void (*handler[LASTEvent])(XEvent *);
diff --git a/src/x11/xutil.h b/src/x11/xutil.h
new file mode 100644
index 0000000..2e044e3
--- /dev/null
+++ b/src/x11/xutil.h
@@ -0,0 +1,21 @@
1
2#pragma once
3
4#include "../core/types.h"
5
6void checkotherwm(void);
7
8Atom getatomprop(Client *c, Atom prop);
9int getrootptr(int *x, int *y);
10long getstate(Window w);
11int gettextprop(Window w, Atom atom, char *text, unsigned int size);
12
13int sendevent(Window w, Atom proto, int m, long d0, long d1, long d2, long d3,
14 long d4);
15
16void setfocus(Client *c);
17void updatenumlockmask(void);
18
19int xerror(Display *dpy, XErrorEvent *ee);
20int xerrordummy(Display *dpy, XErrorEvent *ee);
21int xerrorstart(Display *dpy, XErrorEvent *ee);