Skip to content

Commit

Permalink
Added automatic generation of ewmh atom list and corresponding name m…
Browse files Browse the repository at this point in the history
…apping.

Added a scheme utility to maintain this mapping.
  • Loading branch information
alisabedard committed Jun 11, 2017
1 parent 5d65fdc commit 2d0fd6e
Show file tree
Hide file tree
Showing 15 changed files with 189 additions and 1 deletion.
51 changes: 51 additions & 0 deletions JBWMAtomIndex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2017, Jeffrey E. Bedard
#ifndef JBWM_JBWMATOMINDEX_H
#define JBWM_JBWMATOMINDEX_H
enum JBWMAtomIndex{
JBWM_EWMH_SUPPORTED,
JBWM_EWMH_CURRENT_DESKTOP,
JBWM_EWMH_NUMBER_OF_DESKTOPS,
JBWM_EWMH_DESKTOP_VIEWPORT,
JBWM_EWMH_DESKTOP_GEOMETRY,
JBWM_EWMH_SUPPORTING_WM_CHECK,
JBWM_EWMH_ACTIVE_WINDOW,
JBWM_EWMH_MOVERESIZE_WINDOW,
JBWM_EWMH_CLOSE_WINDOW,
JBWM_EWMH_CLIENT_LIST,
JBWM_EWMH_VIRTUAL_ROOTS,
JBWM_EWMH_CLIENT_LIST_STACKING,
JBWM_EWMH_FRAME_EXTENTS,

JBWM_EWMH_WM_ALLOWED_ACTIONS,
JBWM_EWMH_WM_NAME,
JBWM_EWMH_WM_DESKTOP,
JBWM_EWMH_WM_MOVERESIZE,
JBWM_EWMH_WM_PID,
JBWM_EWMH_WM_WINDOW_TYPE,
JBWM_EWMH_WM_STATE,

JBWM_EWMH_WM_ACTION_MOVE,
JBWM_EWMH_WM_ACTION_RESIZE,
JBWM_EWMH_WM_ACTION_CLOSE,
JBWM_EWMH_WM_ACTION_SHADE,
JBWM_EWMH_WM_ACTION_FULLSCREEN,
JBWM_EWMH_WM_ACTION_CHANGE_DESKTOP,
JBWM_EWMH_WM_ACTION_ABOVE,
JBWM_EWMH_WM_ACTION_BELOW,
JBWM_EWMH_WM_ACTION_MAXIMIZE_HORZ,
JBWM_EWMH_WM_ACTION_MAXIMIZE_VERT,

JBWM_EWMH_WM_STATE_STICKY,
JBWM_EWMH_WM_STATE_MAXIMIZED_VERT,
JBWM_EWMH_WM_STATE_MAXIMIZED_HORZ,
JBWM_EWMH_WM_STATE_SHADED,
JBWM_EWMH_WM_STATE_HIDDEN,
JBWM_EWMH_WM_STATE_FULLSCREEN,
JBWM_EWMH_WM_STATE_ABOVE,
JBWM_EWMH_WM_STATE_BELOW,
JBWM_EWMH_WM_STATE_FOCUSED,

// The following entry must be last:
JBWM_EWMH_ATOMS_COUNT,
};
#endif//JBWM_JBWMATOMINDEX_H
1 change: 1 addition & 0 deletions client.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "client.h"
#include <X11/Xutil.h>
#include <stdlib.h>
#include "JBWMAtomIndex.h"
#include "ewmh.h"
#include "ewmh_state.h"
#include "screen.h"
Expand Down
7 changes: 6 additions & 1 deletion ewmh.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <X11/Xatom.h>
#include <string.h>
#include <unistd.h>
#include "JBWMAtomIndex.h"
#include "JBWMClient.h"
#include "JBWMScreen.h"
#include "client.h"
Expand All @@ -22,6 +23,7 @@ Atom jbwm_ewmh_get_atom(const uint8_t index)
}
static void jbwm_ewmh_init(Display * d)
{
#if 0
static char * atom_names [] = { // This list must match 1:1 with enum
"_NET_SUPPORTED",
"_NET_CURRENT_DESKTOP",
Expand Down Expand Up @@ -63,7 +65,10 @@ static void jbwm_ewmh_init(Display * d)
"_NET_WM_STATE_BELOW",
"_NET_WM_STATE_FOCUSED",
};
XInternAtoms(d, atom_names, JBWM_EWMH_ATOMS_COUNT, false, jbwm_ewmh);
#endif
#include "ewmh_atoms.c"
XInternAtoms(d, jbwm_atom_names,
JBWM_EWMH_ATOMS_COUNT, false, jbwm_ewmh);
}
static inline void wprop(Display * d, const Window win,
const enum JBWMAtomIndex i, const Atom type,
Expand Down
2 changes: 2 additions & 0 deletions ewmh.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void jbwm_ewmh_set_allowed_actions(Display * d,
void jbwm_ewmh_init_screen(Display * d, struct JBWMScreen * s)
__attribute__((nonnull));
void jbwm_set_frame_extents(struct JBWMClient * restrict c);
#if 0
enum JBWMAtomIndex {
JBWM_EWMH_SUPPORTED,
JBWM_EWMH_CURRENT_DESKTOP,
Expand Down Expand Up @@ -60,6 +61,7 @@ enum JBWMAtomIndex {
JBWM_EWMH_ATOMS_COUNT
};
extern Atom ewmh[];
#endif
#else//!JBWM_USE_EWMH
#define jbwm_ewmh_get_atom(i)
#define jbwm_ewmh_set_allowed_actions(d, w)
Expand Down
74 changes: 74 additions & 0 deletions ewmh.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
":";exec guile -s $0 "$@"
; for MIT Scheme
(define copyright "Copyright 2017, Jeffrey E. Bedard")
(define net '("SUPPORTED" "CURRENT_DESKTOP" "NUMBER_OF_DESKTOPS"
"DESKTOP_VIEWPORT" "DESKTOP_GEOMETRY" "SUPPORTING_WM_CHECK"
"ACTIVE_WINDOW" "MOVERESIZE_WINDOW" "CLOSE_WINDOW" "CLIENT_LIST"
"VIRTUAL_ROOTS" "CLIENT_LIST_STACKING" "FRAME_EXTENTS"))
(define wm '("ALLOWED_ACTIONS" "NAME" "DESKTOP" "MOVERESIZE" "PID"
"WINDOW_TYPE" "STATE"))
(define wm-action '("MOVE" "RESIZE" "CLOSE" "SHADE" "FULLSCREEN"
"CHANGE_DESKTOP" "ABOVE" "BELOW" "MAXIMIZE_HORZ" "MAXIMIZE_VERT"))
(define wm-state '("STICKY" "MAXIMIZED_VERT" "MAXIMIZED_HORZ" "SHADED"
"HIDDEN" "FULLSCREEN" "ABOVE" "BELOW" "FOCUSED"))
(define get-copyright-line (lambda ()
(string-append "// " copyright "\n")))
(define begin-array-definition (lambda (name) (begin
(display (string-append (get-copyright-line)
"static char * " name " [] = {\n"))
0)))
(define begin-enum-definition (lambda (name)
(display (string-append "enum " name "{\n"))))
(define end-c-definition (lambda () (display "};\n")))
(define master-prefix "_NET_")
(define print-each (lambda (prefix l)
(if (null? l)
(begin (display "\n") 0)
(begin
(display (string-append "\t\"" master-prefix
prefix (car l) "\",\n"))
(print-each prefix (cdr l))))))
(define print-enum-line (lambda (prefix item)
(display (string-append "\t" master-prefix prefix item ",\n"))))
(define print-each-enum (lambda (prefix l)
(if (null? l)
(begin (display "\n") 0)
(begin
(print-enum-line prefix (car l))
(print-each-enum prefix (cdr l))))))
; (begin (display (string-append
; "\t" master-prefix prefix (car l) ",\n"))
; (print-each-enum prefix (cdr l))))))

; The execution begins:

; For atom_names:
(define f (open-output-file "ewmh_atoms.c"))
(set-current-output-port! f)
(begin-array-definition "jbwm_atom_names")
(print-each "" net)
(print-each "WM_" wm)
(print-each "WM_ACTION_" wm-action)
(print-each "WM_STATE_" wm-state)
(end-c-definition)
;(display "};\n")
(close-port f)

; JBWMAtomIndex:
(define f (open-output-file "JBWMAtomIndex.h"))
(set-current-output-port! f)
(display (string-append
(get-copyright-line)
"#ifndef JBWM_JBWMATOMINDEX_H\n"
"#define JBWM_JBWMATOMINDEX_H\n"))
(begin-enum-definition "JBWMAtomIndex")
(set! master-prefix "JBWM_EWMH_")
(print-each-enum "" net)
(print-each-enum "WM_" wm)
(print-each-enum "WM_ACTION_" wm-action)
(print-each-enum "WM_STATE_" wm-state)
(display "\t// The following entry must be last:\n")
(print-enum-line "" "ATOMS_COUNT")
(end-c-definition)
(display "#endif//JBWM_JBWMATOMINDEX_H\n")
(close-port f)
46 changes: 46 additions & 0 deletions ewmh_atoms.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2017, Jeffrey E. Bedard
static char * jbwm_atom_names [] = {
"_NET_SUPPORTED",
"_NET_CURRENT_DESKTOP",
"_NET_NUMBER_OF_DESKTOPS",
"_NET_DESKTOP_VIEWPORT",
"_NET_DESKTOP_GEOMETRY",
"_NET_SUPPORTING_WM_CHECK",
"_NET_ACTIVE_WINDOW",
"_NET_MOVERESIZE_WINDOW",
"_NET_CLOSE_WINDOW",
"_NET_CLIENT_LIST",
"_NET_VIRTUAL_ROOTS",
"_NET_CLIENT_LIST_STACKING",
"_NET_FRAME_EXTENTS",

"_NET_WM_ALLOWED_ACTIONS",
"_NET_WM_NAME",
"_NET_WM_DESKTOP",
"_NET_WM_MOVERESIZE",
"_NET_WM_PID",
"_NET_WM_WINDOW_TYPE",
"_NET_WM_STATE",

"_NET_WM_ACTION_MOVE",
"_NET_WM_ACTION_RESIZE",
"_NET_WM_ACTION_CLOSE",
"_NET_WM_ACTION_SHADE",
"_NET_WM_ACTION_FULLSCREEN",
"_NET_WM_ACTION_CHANGE_DESKTOP",
"_NET_WM_ACTION_ABOVE",
"_NET_WM_ACTION_BELOW",
"_NET_WM_ACTION_MAXIMIZE_HORZ",
"_NET_WM_ACTION_MAXIMIZE_VERT",

"_NET_WM_STATE_STICKY",
"_NET_WM_STATE_MAXIMIZED_VERT",
"_NET_WM_STATE_MAXIMIZED_HORZ",
"_NET_WM_STATE_SHADED",
"_NET_WM_STATE_HIDDEN",
"_NET_WM_STATE_FULLSCREEN",
"_NET_WM_STATE_ABOVE",
"_NET_WM_STATE_BELOW",
"_NET_WM_STATE_FOCUSED",

};
1 change: 1 addition & 0 deletions ewmh_client.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2017, Jeffrey E. Bedard
#include "ewmh_client.h"
#include "JBWMAtomIndex.h"
#include "client.h"
#include "config.h"
#include "drag.h"
Expand Down
1 change: 1 addition & 0 deletions ewmh_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#undef DEBUG
#include "ewmh_state.h"
#include <X11/Xatom.h>
#include "JBWMAtomIndex.h"
#include "client.h"
#include "drag.h"
#include "ewmh.h"
Expand Down
1 change: 1 addition & 0 deletions ewmh_wm_state.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2017, Jeffrey E. Bedard
#include "ewmh_wm_state.h"
#include "JBWMAtomIndex.h"
#include "JBWMClient.h"
#include "client.h"
#include "ewmh.h"
Expand Down
1 change: 1 addition & 0 deletions max.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2017, Jeffrey E. Bedard
#include "max.h"
#include "JBWMAtomIndex.h"
#include "ewmh.h"
#include "ewmh_state.h"
#include "font.h"
Expand Down
1 change: 1 addition & 0 deletions new.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "new.h"
#include <X11/Xatom.h> // for XA_CARDINAL
#include <stdlib.h>
#include "JBWMAtomIndex.h"
#include "JBWMClient.h"
#include "client.h"
#include "config.h" // for JBWM_MAX_DESKTOPS
Expand Down
1 change: 1 addition & 0 deletions select.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "select.h"
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include "JBWMAtomIndex.h"
#include "client.h"
#include "ewmh.h"
#include "ewmh_state.h"
Expand Down
1 change: 1 addition & 0 deletions title_bar.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "title_bar.h"
#include <X11/Xatom.h>
#include <X11/Xft/Xft.h>
#include "JBWMAtomIndex.h"
#include "config.h"
#include "ewmh.h"
#include "ewmh_state.h"
Expand Down
1 change: 1 addition & 0 deletions vdesk.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// See README for license and other details.
#include "vdesk.h"
#include <X11/Xatom.h> // keep
#include "JBWMAtomIndex.h"
#include "JBWMClient.h"
#include "JBWMScreen.h"
#include "client.h"
Expand Down
1 change: 1 addition & 0 deletions wm_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "wm_state.h"
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include "JBWMAtomIndex.h"
#include "ewmh.h"
#include "ewmh_state.h"
#include "log.h"
Expand Down

0 comments on commit 2d0fd6e

Please sign in to comment.