Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 2 files changed
  • 0 comments
  • 1 contributor

Showing 2 changed files with 1 addition and 843 deletions. Show diff stats Hide diff stats

  1. +0 842 bluckywm.c
  2. +1 1  config.def.h
842 bluckywm.c
... ... @@ -1,842 +0,0 @@
1   -/* beluckywm.c [0.1.4]
2   - * I started this from my port of catwm ( https://bbs.archlinux.org/viewtopic.php?id=100215&p=1 ) july 2011
3   - * With the source for mcwm ( http://hack.org/mc/hacks/mcwm/ ) open in front of me. Cheers for the code sharing :)
4   - *
5   - */
6   -#include <stdio.h>
7   -#include <stdlib.h>
8   -#include <unistd.h>
9   -#include <errno.h>
10   -#include <signal.h>
11   -#include <sys/wait.h>
12   -#include <xcb/xcb.h>
13   -#include <xcb/xcb_atom.h>
14   -#include <xcb/xcb_icccm.h>
15   -
16   -#define TABLENGTH(X) (sizeof(X)/sizeof(*X))
17   -
18   -typedef union {
19   - const char** com;
20   - const int i;
21   -} Arg;
22   -
23   -typedef struct {
24   - unsigned int mod;
25   - unsigned int keysym;
26   - void (*function)(const Arg arg);
27   - const Arg arg;
28   -} key;
29   -
30   -typedef struct client client;
31   -struct client{
32   - // Prev and next client
33   - client *next;
34   - client *prev;
35   -
36   - // The window
37   - xcb_window_t win;
38   -};
39   -
40   -typedef struct desktop desktop;
41   -struct desktop{
42   - int master_size;
43   - int mode;
44   - client *head;
45   - client *current;
46   -};
47   -
48   -static void add_window(xcb_window_t w);
49   -static void remove_window(xcb_window_t w);
50   -static void decrease();
51   -static void increase();
52   -static void kill_client();
53   -static void move_down();
54   -static void move_up();
55   -static void next_win();
56   -static void prev_win();
57   -static void quit();
58   -static void swap_master();
59   -
60   -static void change_desktop(const Arg arg);
61   -static void client_to_desktop(const Arg arg);
62   -static void next_desktop();
63   -static void prev_desktop();
64   -static void save_desktop(int i);
65   -static void select_desktop(int i);
66   -static void switch_horizontal();
67   -static void switch_vertical();
68   -static void switch_grid();
69   -static void tile();
70   -static void toggle_fullscreen();
71   -static void update_current();
72   -
73   -static void grabkeys();
74   -static void keypress(xcb_key_press_event_t *ev);
75   -
76   -static void events();
77   -static void sigchld(int unused);
78   -static void cleanup(int code);
79   -static void spawn(const Arg arg);
80   -
81   -static void logger(const char* e);
82   -
83   -static int current_desktop;
84   -static int master_size;
85   -static int mode;
86   -static int sh;
87   -static int sw;
88   -static int sigcode;
89   -static int holder; // for coming out of fullscreen mode back to what mode it was
90   -
91   -xcb_connection_t *conn; /* Connection to X server. */
92   -xcb_screen_t *screen; /* Our current screen. */
93   -xcb_colormap_t colormap; /* our colourmap connection */
94   -static client *head;
95   -static client *current;
96   -xcb_atom_t atom_desktop;
97   -xcb_atom_t wm_delete_window;
98   -xcb_atom_t wm_protocols;
99   -
100   -#include "config.h"
101   -
102   -static desktop desktops[6];
103   -
104   -/* ***************************** Window Management ******************************* */
105   -void add_window(xcb_window_t w) {
106   - client *c,*t;
107   -
108   - c = malloc(sizeof (c));
109   - if (NULL == c) {
110   - logger("\033[0;31m Error calloc!");
111   - exit(1);
112   - }
113   -
114   - if(head == NULL) {
115   - c->next = NULL;
116   - c->prev = NULL;
117   - c->win = w;
118   - head = c;
119   - }
120   - else {
121   - if(ATTACH_ASIDE == 0) {
122   - for(t=head;t->next;t=t->next);
123   - c->next = NULL;
124   - c->prev = t;
125   - c->win = w;
126   - t->next = c;
127   - }
128   - else {
129   - for(t=head;t->prev;t=t->prev);
130   - c->prev = NULL;
131   - c->next = t;
132   - c->win = w;
133   - t->prev = c;
134   - head = c;
135   - }
136   - }
137   -
138   - current = c;
139   - save_desktop(current_desktop);
140   -}
141   -
142   -void remove_window(xcb_window_t w) {
143   - client *c;
144   -
145   - for(c=head;c;c=c->next) {
146   - if(c->win == w) {
147   - if(c->prev == NULL && c->next == NULL) {
148   - free(head);
149   - head = NULL;
150   - current = NULL;
151   - return;
152   - }
153   -
154   - if(c->prev == NULL) {
155   - head = c->next;
156   - c->next->prev = NULL;
157   - current = c->next;
158   - }
159   - else if(c->next == NULL) {
160   - c->prev->next = NULL;
161   - current = c->prev;
162   - }
163   - else {
164   - c->prev->next = c->next;
165   - c->next->prev = c->prev;
166   - current = c->prev;
167   - }
168   -
169   - free(c);
170   - save_desktop(current_desktop);
171   - return;
172   - }
173   - }
174   -}
175   -
176   -void kill_client() {
177   - client *c;
178   - xcb_get_property_cookie_t cookie;
179   - xcb_get_wm_protocols_reply_t protocols;
180   - int deletewin = 0;
181   - uint32_t i;
182   -
183   - for(c=head;c;c=c->next) {
184   - if(c == current) {
185   - /* Check if WM_DELETE is supported. */
186   - atom_desktop = xcb_atom_get(conn, "_NET_WM_DESKTOP");
187   - wm_delete_window = xcb_atom_get(conn, "WM_DELETE_WINDOW");
188   - wm_protocols = xcb_atom_get(conn, "WM_PROTOCOLS");
189   - cookie = xcb_get_wm_protocols_unchecked(conn, c->win, wm_protocols);
190   - if (xcb_get_wm_protocols_reply(conn, cookie, &protocols, NULL) == 1) {
191   - for (i = 0; i < protocols.atoms_len; i++)
192   - if (protocols.atoms[i] == wm_delete_window)
193   - deletewin = 1;
194   - }
195   - xcb_get_wm_protocols_reply_wipe(&protocols);
196   - if (deletewin == 1) {
197   - xcb_client_message_event_t ev = {.response_type = XCB_CLIENT_MESSAGE, .format = 32, .sequence = 0, .window = c->win, .type = wm_protocols, .data.data32 = { wm_delete_window, XCB_CURRENT_TIME }};
198   - xcb_send_event(conn, 0, c->win, XCB_EVENT_MASK_NO_EVENT, (char *) &ev);
199   - }
200   - else {
201   - xcb_kill_client(conn, c->win);
202   - }
203   - xcb_flush(conn);
204   - }
205   - }
206   -}
207   -
208   -void move_down() {
209   - xcb_window_t tmp;
210   - if(current == NULL || current->next == NULL || current->win == head->win || current->prev == NULL)
211   - return;
212   -
213   - tmp = current->win;
214   - current->win = current->next->win;
215   - current->next->win = tmp;
216   - //keep the moved window activated
217   - next_win();
218   - save_desktop(current_desktop);
219   - tile();
220   -}
221   -
222   -void move_up() {
223   - xcb_window_t tmp;
224   - if(current == NULL || current->prev == head || current->win == head->win) {
225   - return;
226   - }
227   - tmp = current->win;
228   - current->win = current->prev->win;
229   - current->prev->win = tmp;
230   - prev_win();
231   - save_desktop(current_desktop);
232   - tile();
233   -}
234   -
235   -void next_win() {
236   - client *c;
237   -
238   - if(current != NULL && head != NULL) {
239   - if(current->next == NULL)
240   - c = head;
241   - else
242   - c = current->next;
243   -
244   - current = c;
245   - if(mode == 1)
246   - tile();
247   - update_current();
248   - }
249   -}
250   -
251   -void prev_win() {
252   - client *c;
253   -
254   - if(current != NULL && head != NULL) {
255   - if(current->prev == NULL)
256   - for(c=head;c->next;c=c->next);
257   - else
258   - c = current->prev;
259   -
260   - current = c;
261   - if(mode == 1)
262   - tile();
263   - update_current();
264   - }
265   -}
266   -
267   -void swap_master() {
268   - xcb_window_t tmp;
269   -
270   - if(head != NULL && current != NULL && mode != 1) {
271   - if(current == head) {
272   - tmp = head->next->win;
273   - head->next->win = head->win;
274   - head->win = tmp;
275   - current = head;
276   - } else {
277   - tmp = head->win;
278   - head->win = current->win;
279   - current->win = tmp;
280   - current = head;
281   - }
282   - save_desktop(current_desktop);
283   - tile();
284   - update_current();
285   - }
286   -}
287   -
288   -void decrease() {
289   - master_size -= 10;
290   - tile();
291   -}
292   -
293   -void increase() {
294   - master_size += 10;
295   - tile();
296   -}
297   -
298   -/* ********************** Desktop Management *********************** */
299   -
300   -void change_desktop(const Arg arg) {
301   - client *c;
302   -
303   - if(arg.i == current_desktop)
304   - return;
305   -
306   - // Save current "properties"
307   - save_desktop(current_desktop);
308   -
309   - // Unmap all window
310   - if(head != NULL)
311   - for(c=head;c;c=c->next)
312   - xcb_unmap_window(conn, c->win);
313   -
314   - // Take "properties" from the new desktop
315   - select_desktop(arg.i);
316   -
317   - // Map all windows
318   - if(head != NULL)
319   - for(c=head;c;c=c->next)
320   - xcb_map_window(conn, c->win);
321   -
322   - tile();
323   - update_current();
324   -
325   -}
326   -
327   -void next_desktop() {
328   - int tmp = current_desktop;
329   - if(tmp == 5)
330   - tmp = 0;
331   - else
332   - tmp++;
333   -
334   - Arg a = {.i = tmp};
335   - change_desktop(a);
336   -}
337   -
338   -void prev_desktop() {
339   - int tmp = current_desktop;
340   - if(tmp == 0)
341   - tmp = 5;
342   - else
343   - tmp--;
344   -
345   - Arg a = {.i = tmp};
346   - change_desktop(a);
347   -}
348   -
349   -void client_to_desktop(const Arg arg) {
350   - client *tmp = current;
351   - int tmp2 = current_desktop;
352   -
353   - if(arg.i == current_desktop || current == NULL)
354   - return;
355   -
356   - // Add client to desktop
357   - select_desktop(arg.i);
358   - add_window(tmp->win);
359   - save_desktop(arg.i);
360   -
361   - // Remove client from current desktop
362   - select_desktop(tmp2);
363   - xcb_unmap_window(conn,tmp->win);
364   - remove_window(tmp->win);
365   - save_desktop(tmp2);
366   - tile();
367   - update_current();
368   -
369   - if(FOLLOW_WINDOW == 0)
370   - change_desktop(arg);
371   -}
372   -
373   -void save_desktop(int i) {
374   - desktops[i].master_size = master_size;
375   - desktops[i].mode = mode;
376   - desktops[i].head = head;
377   - desktops[i].current = current;
378   -}
379   -
380   -void select_desktop(int i) {
381   - head = desktops[i].head;
382   - current = desktops[i].current;
383   - master_size = desktops[i].master_size;
384   - mode = desktops[i].mode;
385   - current_desktop = i;
386   -}
387   -
388   -void tile() {
389   - client *c;
390   - int n = 0;
391   - int x = 0;
392   - int y = 0;
393   -
394   - // For a top panel
395   - if(TOP_PANEL == 0)
396   - y = PANEL_HEIGHT;
397   -
398   - // If only one window
399   - if(head != NULL && head->next == NULL) {
400   - uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
401   - uint32_t values[4] = {0, y, sw, sh};
402   - xcb_configure_window (conn, head->win, mask, values);
403   - }
404   - else if(head != NULL) {
405   - switch(mode) {
406   - case 0: { // Horizontal
407   - // Master window
408   - uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
409   - uint32_t values[4] = {0, y, sw, master_size-2*BORDER_WIDTH};
410   - xcb_configure_window (conn, head->win, mask, values);
411   -
412   - // Stack
413   - for(c=head->next;c;c=c->next) ++n;
414   - for(c=head->next;c;c=c->next) {
415   - uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
416   - uint32_t values[4] = {x, y+master_size, (sw/n), sh-master_size};
417   - xcb_configure_window (conn, c->win, mask, values);
418   - x += sw/n;
419   - }
420   - }
421   - break;
422   - case 1: // Fullscreen
423   - for(c=head;c;c=c->next) {
424   - if(c == current) {
425   - uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
426   - uint32_t values[4] = {0, y, sw+(2*BORDER_WIDTH), sh+(2*BORDER_WIDTH)};
427   - xcb_configure_window (conn, c->win, mask, values);
428   - }
429   - }
430   - break;
431   - case 2: { // Vertical
432   - // Master window
433   - uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
434   - uint32_t values[4] = {0, y, master_size-(2*BORDER_WIDTH), sh};
435   - xcb_configure_window (conn, head->win, mask, values);
436   -
437   - // Stack
438   - for(c=head->next;c;c=c->next) ++n;
439   - for(c=head->next;c;c=c->next) {
440   - uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
441   - uint32_t values[4] = {master_size, y, sw-master_size, sh/n};
442   - xcb_configure_window (conn, c->win, mask, values);
443   - y += sh/n;
444   - }
445   - }
446   - break;
447   - case 3: { // Grid
448   - int xpos = 0;
449   - int wdt = 0;
450   - int ht = 0;
451   -
452   - for(c=head;c;c=c->next) {
453   - ++n;
454   - if((n == 1) || (n == 3) || (n == 5) || (n == 7))
455   - x += 1;
456   - }
457   - n = 0;
458   - for(c=head;c;c=c->next) {
459   - ++n;
460   - if(x == 4) {
461   - wdt = (sw/3) - BORDER_WIDTH;
462   - ht = (sh/3) - BORDER_WIDTH;
463   - if((n == 1) || (n == 4) || (n == 7))
464   - xpos = 0;
465   - if((n == 2) || (n == 5) || (n == 8))
466   - xpos = (sw/3) + BORDER_WIDTH;
467   - if((n == 3) || (n == 6) || (n == 9))
468   - xpos = (2*(sw/3)) + BORDER_WIDTH;
469   - if((n == 4) || (n == 7))
470   - y += (sh/3) + BORDER_WIDTH;
471   - } else
472   - if(x == 3) {
473   - wdt = (sw/3) - BORDER_WIDTH;
474   - ht = (sh/2) - BORDER_WIDTH;
475   - if((n == 1) || (n == 4))
476   - xpos = 0;
477   - if((n == 2) || (n == 5))
478   - xpos = (sw/3) + BORDER_WIDTH;
479   - if((n == 3) || (n == 6))
480   - xpos = (2*(sw/3)) + BORDER_WIDTH;
481   - if(n == 4)
482   - y = (sh/2) + BORDER_WIDTH;
483   - } else {
484   - if(n > 2)
485   - ht = (sh/x) - 2*BORDER_WIDTH;
486   - else
487   - ht = sh/x;
488   - if((n == 1) || (n == 3)) {
489   - xpos = 0;
490   - wdt = master_size - BORDER_WIDTH;
491   - }
492   - if((n == 2) || (n == 4)) {
493   - xpos = master_size+BORDER_WIDTH;
494   - wdt = (sw - master_size) - BORDER_WIDTH;
495   - }
496   - if(n == 3)
497   - y += (sh/x)+2*BORDER_WIDTH;
498   - }
499   -
500   - uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
501   - uint32_t values[4] = {xpos, y, wdt, ht};
502   - xcb_configure_window (conn, c->win, mask, values);
503   - }
504   - }
505   - break;
506   - default:
507   - break;
508   - }
509   - }
510   -}
511   -
512   -void update_current() {
513   - client *c;
514   - int bw;
515   - xcb_alloc_color_cookie_t colcookie;
516   - xcb_alloc_color_reply_t *reply;
517   - uint32_t values[2];
518   -
519   - for(c=head;c;c=c->next)
520   - if(current == c) {
521   - // "Enable" current window
522   - if((mode == 1) && (head->next != NULL))
523   - bw = 0;
524   - else
525   - bw = BORDER_WIDTH;
526   - colcookie = xcb_alloc_color (conn, colormap, 33000, 20000, 10000);
527   - reply = xcb_alloc_color_reply (conn, colcookie, NULL);
528   - values[0] = reply->pixel;
529   - xcb_change_window_attributes(conn, c->win, XCB_CW_BORDER_PIXEL, values);
530   - values[0] = bw;
531   - values[1] = ( XCB_STACK_MODE_ABOVE );
532   - xcb_configure_window(conn, c->win, XCB_CONFIG_WINDOW_BORDER_WIDTH|XCB_CONFIG_WINDOW_STACK_MODE, values);
533   - xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, c->win, XCB_CURRENT_TIME);
534   - free (reply);
535   - }
536   - else {
537   - colcookie = xcb_alloc_color (conn, colormap, 0, 16000, 19000);
538   - reply = xcb_alloc_color_reply (conn, colcookie, NULL);
539   - values[0] = reply->pixel;
540   - xcb_change_window_attributes(conn, c->win, XCB_CW_BORDER_PIXEL, values);
541   - values[0] = BORDER_WIDTH;
542   - values[1] = ( XCB_STACK_MODE_BELOW );
543   - xcb_configure_window(conn, c->win, XCB_CONFIG_WINDOW_BORDER_WIDTH|XCB_CONFIG_WINDOW_STACK_MODE, values);
544   - free (reply);
545   - }
546   -
547   - xcb_flush(conn);
548   -}
549   -
550   -void toggle_fullscreen() {
551   - if(mode != 1) {
552   - holder = mode;
553   - mode = 1;
554   - } else {
555   - mode = holder;
556   - }
557   -
558   - tile();
559   - update_current();
560   -}
561   -
562   -void switch_vertical() {
563   - if(mode != 2) {
564   - mode = 2;
565   - master_size = sw * MASTER_SIZE;
566   - tile();
567   - update_current();
568   - }
569   -}
570   -
571   -void switch_horizontal() {
572   - if(mode != 0) {
573   - mode = 0;
574   - master_size = sh * MASTER_SIZE;
575   - tile();
576   - update_current();
577   - }
578   -}
579   -
580   -void switch_grid() {
581   - if(mode != 3) {
582   - mode = 3;
583   - master_size = sw * MASTER_SIZE;
584   - tile();
585   - update_current();
586   - }
587   -}
588   -
589   -/* ********************** Keyboard Management ********************** */
590   -void grabkeys() {
591   - int i;
592   -
593   - // For each shortcuts
594   - for(i=0;i<TABLENGTH(keys);++i) {
595   - // for the first run uncomment the following line to find your modifier keys then recomment it or your apps won't get keyboard control
596   - //xcb_grab_key(conn, 1, screen->root, XCB_MOD_MASK_ANY, keys[i].keysym, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
597   - xcb_grab_key(conn, 1, screen->root, keys[i].mod, keys[i].keysym, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
598   - }
599   - xcb_flush(conn);
600   -}
601   -
602   -void keypress(xcb_key_press_event_t *ev) {
603   - static unsigned int len = sizeof keys / sizeof keys[0];
604   - unsigned int i;
605   -
606   - for(i = 0; i < len; i++) {
607   - if(ev->detail == keys[i].keysym && ev->state == keys[i].mod) {
608   - // To find out what you're keys are mapped to uncomment the following line
609   - //fprintf(stdout, "\033[0;32m modifier key is = %d,\033[0;33m config has = %d\n \033[0;32m key pressed = %d, \033[0;33m config has = %d\033[0m \n", ev->state, keys[i].mod, ev->detail, keys[i].keysym);
610   - if(keys[i].function)
611   - keys[i].function(keys[i].arg);
612   -
613   - xcb_flush(conn);
614   - return;
615   - }
616   - }
617   - xcb_send_event(conn, 1, XCB_SEND_EVENT_DEST_ITEM_FOCUS, XCB_EVENT_MASK_NO_EVENT, (char *) ev);
618   -}
619   -
620   -
621   -/********************************* Signals *****************************************/
622   -
623   -void logger(const char* e) {
624   - fprintf(stdout, "\033[0;34m :: beluckywm : %s\033[0m\n", e);
625   -}
626   -
627   -void cleanup(int code)
628   -{
629   - xcb_set_input_focus(conn, XCB_NONE, XCB_INPUT_FOCUS_POINTER_ROOT, XCB_CURRENT_TIME);
630   - xcb_flush(conn);
631   - xcb_disconnect(conn);
632   - logger("\033[0;32m Cleaned up and am gone :)");
633   - exit(code);
634   -}
635   -
636   -void events() {
637   - xcb_generic_event_t *ev;
638   -
639   - int fd; /* Our X file descriptor */
640   - fd_set in; /* For select */
641   - int found; /* Ditto. */
642   -
643   - /* Get the file descriptor so we can do select() on it. */
644   - fd = xcb_get_file_descriptor(conn);
645   -
646   - for (sigcode = 0; 0 == sigcode;) {
647   - /* Prepare for select(). */
648   - FD_ZERO(&in);
649   - FD_SET(fd, &in);
650   -
651   - /* Check for events, again and again. When poll returns NULL, we block on select() until the event file descriptor gets readable again. We do it this way instead of xcb_wait_for_event() since select() will return if we we're interrupted by a signal. We like that.*/
652   - ev = xcb_poll_for_event(conn);
653   - if (NULL == ev) {
654   - found = select(fd + 1, &in, NULL, NULL, NULL);
655   - if (-1 == found) {
656   - if (EINTR == errno) {
657   - /* We received a signal. Break out of loop. */
658   - break;
659   - }
660   - else
661   - { /* Something was seriously wrong with select(). */
662   - logger("\033[0;31m select failed.");
663   - cleanup(0);
664   - exit(1);
665   - }
666   - }
667   - else
668   - {/* We found more events. Goto start of loop. */
669   - continue;
670   - }
671   - }
672   - switch (ev->response_type & ~0x80) {
673   - case XCB_MAP_REQUEST: {
674   - int y = 0;
675   - xcb_map_request_event_t *e;
676   -
677   - e = (xcb_map_request_event_t *) ev;
678   - // For fullscreen mplayer (and maybe some other program)
679   - if(TOP_PANEL == 0)
680   - y = PANEL_HEIGHT;
681   - client *c;
682   - for(c=head;c;c=c->next)
683   - if(e->window == c->win) {
684   - uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
685   - uint32_t values[6] = {0, y, sw, sh};
686   - xcb_configure_window (conn, c->win, mask, values);
687   - xcb_map_window(conn,c->win);
688   - update_current();
689   - return;
690   - }
691   -
692   - add_window(e->window);
693   - xcb_map_window(conn, e->window);
694   - tile();
695   - update_current();
696   - }
697   - break;
698   -
699   - case XCB_DESTROY_NOTIFY: {
700   - int i = 0;
701   - client *c;
702   - xcb_destroy_notify_event_t *e;
703   -
704   - e = (xcb_destroy_notify_event_t *) ev;
705   - for(c=head;c;c=c->next)
706   - if(e->window == c->win)
707   - ++i;
708   -
709   - if(i != 0) {
710   - remove_window(e->window);
711   - tile();
712   - update_current();
713   - }
714   - }
715   - break;
716   -
717   - case XCB_ENTER_NOTIFY: {
718   - xcb_enter_notify_event_t *e = (xcb_enter_notify_event_t *)ev;
719   - client *c;
720   -
721   - if (e->mode != XCB_NOTIFY_MODE_NORMAL || e->mode != XCB_NOTIFY_MODE_UNGRAB) {
722   - for(c=head;c;c=c->next)
723   - if(e->event == c->win) {
724   - current = c;
725   - update_current();
726   - } else {
727   - return;
728   - }
729   - }
730   - }
731   - break;
732   -
733   - case XCB_KEY_PRESS: {
734   - xcb_key_press_event_t *e = (xcb_key_press_event_t *)ev;
735   -
736   - keypress(e);
737   - }
738   - break;
739   -
740   - }
741   - free(ev);
742   - }
743   -}
744   -
745   -void sigchld(int unused) {
746   - // Again, thx to dwm ;)
747   - if(signal(SIGCHLD, sigchld) == SIG_ERR) {
748   - logger("\033[0;31mCan't install SIGCHLD handler\n");
749   - exit(1);
750   - }
751   - while(0 < waitpid(-1, NULL, WNOHANG));
752   -}
753   -
754   -void spawn(const Arg arg) {
755   - if(fork() == 0) {
756   - if(fork() == 0) {
757   - if(conn)
758   - close(screen->root);
759   -
760   - setsid();
761   - execvp((char*)arg.com[0],(char**)arg.com);
762   - }
763   - exit(0);
764   - }
765   -}
766   -
767   -void quit() {
768   - logger("\033[0;32m You're leaving...?");
769   - cleanup(0);
770   -}
771   -
772   -int main () {
773   - xcb_void_cookie_t cookie;
774   - xcb_generic_error_t *error;
775   - xcb_drawable_t root;
776   -
777   - // Install a signal
778   - sigchld(0);
779   -
780   - conn = xcb_connect(NULL, NULL);
781   - if (xcb_connection_has_error(conn)) {
782   - logger("\033[0;31m xcb_connect!");
783   - exit(1);
784   - }
785   -
786   - /* Get the first screen */
787   - screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data;
788   - root = screen->root;
789   - sw = screen->width_in_pixels-(2*BORDER_WIDTH);
790   - sh = (screen->height_in_pixels-PANEL_HEIGHT)-BORDER_WIDTH;
791   - colormap = screen->default_colormap;
792   -
793   - // Default tiling
794   - mode = DEFAULT_MODE;
795   - if(mode == 0)
796   - master_size = sh*MASTER_SIZE;
797   - else
798   - master_size = sw*MASTER_SIZE;
799   -
800   - head = NULL;
801   - current = NULL;
802   -
803   - // initiate desktops
804   - int i;
805   - for(i=0;i<TABLENGTH(desktops);++i) {
806   - desktops[i].master_size = master_size;
807   - desktops[i].mode = mode;
808   - desktops[i].head = head;
809   - desktops[i].current = current;
810   - }
811   - const Arg arg = {.i = 0};
812   - current_desktop = arg.i;
813   - change_desktop(arg);
814   -
815   - grabkeys();
816   - fprintf(stdout, "\033[0;33m :: beluckywm : %dX%d\033[0m \n", sw, sh);
817   -
818   - // initiate events
819   - uint32_t mask = XCB_CW_EVENT_MASK;
820   - uint32_t values[1] = {XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY};
821   -
822   - // Check if there's another wm running
823   - cookie = xcb_change_window_attributes_checked(conn, root, mask, values);
824   - error = xcb_request_check(conn, cookie);
825   - xcb_flush(conn);
826   - if (NULL != error) {
827   - fprintf(stderr, "\033[0;31m :: beluckywm : Can't get SUBSTRUCTURE REDIRECT. "
828   - "Error code: %d\n"
829   - "\t\t Another window manager running? Exiting.\033[0m \n",
830   - error->error_code);
831   -
832   - xcb_disconnect(conn);
833   - exit(1);
834   - }
835   -
836   - while(1) {
837   - /* Loop over events. */
838   - events();
839   - }
840   -
841   - exit(0);
842   -}
2  config.def.h
... ... @@ -1,4 +1,4 @@
1   -/* config.h for bluckywm.c [0.1.4]*/
  1 +/* config.h for beluckywm.c [0.1.4]*/
2 2
3 3 #ifndef CONFIG_H
4 4 #define CONFIG_H

No commit comments for this range

Something went wrong with that request. Please try again.