Skip to content

Commit 3c808ee

Browse files
committed
Initial version
0 parents  commit 3c808ee

File tree

11 files changed

+1174
-0
lines changed

11 files changed

+1174
-0
lines changed

LICENSE

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ISC License
2+
3+
Copyright (c) 2021, Tommi Leino <[email protected]>
4+
5+
Permission to use, copy, modify, and/or distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Makefile.in

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
SHELL = /bin/sh
2+
CFLAGS = -g -Wall -pedantic -std=c99 @PKGS_CFLAGS@ -DTRACE
3+
LDFLAGS = @PKGS_LDFLAGS@
4+
5+
prefix = @prefix@
6+
exec_prefix = $(prefix)
7+
bindir = $(exec_prefix)/bin
8+
libdir = $(exec_prefix)/lib
9+
datarootdir = $(prefix)/share
10+
mandir = $(datarootdir)/man
11+
12+
INSTALL ?= install
13+
INSTALLFLAGS ?=
14+
15+
SRCS=mxswm.c stack.c client.c event.c menu.c keyboard.c
16+
PROG=mxswm
17+
18+
OBJS=$(SRCS:.c=.o)
19+
20+
all: $(PROG)
21+
22+
$(PROG): $(OBJS)
23+
$(CC) -o$@ $(OBJS) $(LDFLAGS)
24+
25+
.c.o:
26+
$(CC) $(CFLAGS) -c $<
27+
28+
clean:
29+
rm -f $(OBJS) $(PROG)
30+
31+
install: $(PROG)
32+
if [ ! -x $(DESTDIR)$(bindir) ] ; then \
33+
mkdir -p $(DESTDIR)$(bindir) ; fi
34+
$(INSTALL) $(INSTALLFLAGS) $(PROG) $(DESTDIR)$(bindir)
35+
36+
uninstall:
37+
if [ -e $(DESTDIR)$(bindir)/$(PROG) ] ; then \
38+
rm $(DESTDIR)$(bindir)/$(PROG) ; fi

README

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
MaXed Stacks Window Manager for X11
2+
3+
A simpler alternative for https://github.com/tleino/cocowm
4+
by the same author.
5+
6+
(work in progress)

client.c

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
/*
2+
* ISC License
3+
*
4+
* Copyright (c) 2021, Tommi Leino <[email protected]>
5+
*
6+
* Permission to use, copy, modify, and/or distribute this software for any
7+
* purpose with or without fee is hereby granted, provided that the above
8+
* copyright notice and this permission notice appear in all copies.
9+
*
10+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17+
*/
18+
19+
#include "mxswm.h"
20+
21+
#include <assert.h>
22+
#include <err.h>
23+
#include <stdlib.h>
24+
25+
struct client {
26+
Window window;
27+
char *name;
28+
struct client *next;
29+
struct client *prev;
30+
};
31+
32+
static struct client *_head;
33+
static struct client *_focus;
34+
35+
struct client *
36+
add_client(Window window, struct client *after)
37+
{
38+
struct client *client;
39+
40+
client = malloc(sizeof(struct client));
41+
if (client == NULL)
42+
return NULL;
43+
44+
client->window = window;
45+
46+
client->prev = after;
47+
if (after != NULL) {
48+
client->next = after->next;
49+
after->next = client;
50+
} else {
51+
client->next = _head;
52+
if (_head != NULL)
53+
_head->prev = client;
54+
_head = client;
55+
}
56+
57+
if (XFetchName(display(), window, &client->name) == 0)
58+
warnx("unable to fetch name");
59+
60+
focus_client(client);
61+
return client;
62+
}
63+
64+
char *
65+
client_name(struct client *client)
66+
{
67+
return client->name;
68+
}
69+
70+
struct client *
71+
find_client(Window window)
72+
{
73+
struct client *np;
74+
75+
for (np = _head; np != NULL; np = np->next) {
76+
if (np->window != window)
77+
continue;
78+
79+
return np;
80+
}
81+
82+
return add_client(window, NULL);
83+
}
84+
85+
struct client *
86+
next_client(struct client *prev)
87+
{
88+
if (prev == NULL)
89+
return _head;
90+
else
91+
return prev->next;
92+
}
93+
94+
struct client *
95+
prev_client(struct client *client)
96+
{
97+
struct client *np;
98+
99+
if (client == NULL)
100+
return _head;
101+
if (client->prev == NULL) {
102+
np = client;
103+
while (np && np->next)
104+
np = np->next;
105+
return np;
106+
}
107+
return client->prev;
108+
}
109+
110+
void
111+
remove_client(struct client *client)
112+
{
113+
struct client *np;
114+
115+
focus_client_forward();
116+
117+
for (np = _head; np != NULL; np = np->next) {
118+
if (np != client)
119+
continue;
120+
121+
if (np->next != NULL)
122+
np->next->prev = np->prev;
123+
if (np->prev != NULL)
124+
np->prev->next = np->next;
125+
else if (np == _head)
126+
_head = np->next;
127+
free(client);
128+
break;
129+
}
130+
}
131+
132+
void
133+
focus_client(struct client *client)
134+
{
135+
Display *dpy = display();
136+
struct stack *stack = current_stack();
137+
Window window;
138+
139+
if (_focus != NULL) {
140+
window = _focus->window;
141+
XSetWindowBorderWidth(dpy, window, BORDERWIDTH);
142+
XSetWindowBorder(dpy, window, 5485488);
143+
}
144+
145+
_focus = client;
146+
if (_focus == NULL)
147+
return;
148+
149+
window = _focus->window;
150+
XMoveWindow(dpy, window, STACK_X(stack), STACK_Y(stack));
151+
XResizeWindow(dpy, window, STACK_WIDTH(stack), STACK_HEIGHT(stack));
152+
XSetWindowBorderWidth(dpy, window, BORDERWIDTH);
153+
XSetWindowBorder(dpy, window, 434545456);
154+
XRaiseWindow(dpy, window);
155+
XSetInputFocus(dpy, window, RevertToPointerRoot, CurrentTime);
156+
stack->client = client;
157+
}
158+
159+
void
160+
focus_client_forward()
161+
{
162+
struct client *client;
163+
164+
client = current_client();
165+
if (client == NULL)
166+
return;
167+
168+
focus_client(client->next != NULL ? client->next : _head);
169+
}
170+
171+
void
172+
focus_client_backward()
173+
{
174+
struct client *client, *np;
175+
176+
client = current_client();
177+
if (client == NULL)
178+
return;
179+
180+
if (client->prev != NULL)
181+
np = client->prev;
182+
else {
183+
np = client;
184+
while (np->next != NULL)
185+
np = np->next;
186+
assert(np != NULL);
187+
}
188+
189+
focus_client(np);
190+
}
191+
192+
struct client *
193+
current_client()
194+
{
195+
if (_head != NULL && _focus == NULL)
196+
focus_client(_head);
197+
198+
return _focus;
199+
}
200+
201+
#if (TRACE || TEST)
202+
#include <inttypes.h>
203+
#include <stdio.h>
204+
void
205+
dump_client(struct client *client)
206+
{
207+
printf("client: %ju", (uintmax_t) client);
208+
if (client == _focus)
209+
printf(" (focused)");
210+
putchar('\n');
211+
}
212+
213+
void
214+
dump_clients()
215+
{
216+
struct client *np;
217+
218+
printf("focus: %ju\n", (uintmax_t) current_client());
219+
for (np = _head; np != NULL; np = np->next)
220+
dump_client(np);
221+
}
222+
#endif
223+
#if TEST
224+
int
225+
main(int argc, char *argv[])
226+
{
227+
add_client(NULL);
228+
add_client(NULL);
229+
remove_client(current_client());
230+
add_client(current_client());
231+
dump_clients();
232+
}
233+
#endif

configure

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/sh
2+
# Usage: ./configure [install prefix]
3+
4+
check_pkg() {
5+
PKG=$1
6+
7+
echo "pkg-config ${PKG}"
8+
pkg-config $PKG
9+
RET=$?
10+
if [ "${RET}" -eq 127 ] ; then
11+
echo "You need to have pkg-config."
12+
exit 1
13+
elif [ "${RET}" -ne 0 ] ; then
14+
echo "You need to have '${PKG}' package installed."
15+
if [ "${PKG_CONFIG_PATH}" != "" ] ; then
16+
echo "PKG_CONFIG_PATH=${PKG_CONFIG_PATH}"
17+
else
18+
echo "Note: PKG_CONFIG_PATH is not set."
19+
fi
20+
exit 1
21+
fi
22+
}
23+
24+
prefix=/usr/local
25+
if [ "$#" -eq 1 ] ; then prefix=$1 ; fi
26+
echo "prefix=${prefix}"
27+
28+
PKGS="x11 xinerama"
29+
for a in ${PKGS} ; do
30+
check_pkg $a
31+
done
32+
33+
PKGS_CFLAGS=$(pkg-config ${PKGS} --cflags)
34+
PKGS_LDFLAGS=$(pkg-config ${PKGS} --libs)
35+
echo "PKGS_CFLAGS=${PKGS_CFLAGS}"
36+
echo "PKGS_LDFLAGS=${PKGS_LDFLAGS}"
37+
38+
echo "create: Makefile"
39+
echo '# Automatically generated from Makefile.in by configure' >Makefile
40+
echo >>Makefile
41+
sed \
42+
-e "s|@prefix@|${prefix}|g" \
43+
-e "s|@PKGS_CFLAGS@|${PKGS_CFLAGS}|g" \
44+
-e "s|@PKGS_LDFLAGS@|${PKGS_LDFLAGS}|g" \
45+
Makefile.in >>Makefile

event.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* ISC License
3+
*
4+
* Copyright (c) 2021, Tommi Leino <[email protected]>
5+
*
6+
* Permission to use, copy, modify, and/or distribute this software for any
7+
* purpose with or without fee is hereby granted, provided that the above
8+
* copyright notice and this permission notice appear in all copies.
9+
*
10+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17+
*/
18+
19+
#include "mxswm.h"
20+
21+
int
22+
handle_event(XEvent *event)
23+
{
24+
if (event->type == KeyRelease)
25+
do_keyaction(&(event->xkey));
26+
return 1;
27+
}

0 commit comments

Comments
 (0)