Port Awesome to XCB
This commit is contained in:
parent
7e301b5ef2
commit
dafafd077c
22
Makefile.am
22
Makefile.am
|
@ -110,7 +110,12 @@ AWESOME_CFLAGS = -std=gnu99 -pipe \
|
|||
-Wunused -Winit-self -Wpointer-arith -Wredundant-decls \
|
||||
-Wmissing-prototypes -Wmissing-format-attribute -Wmissing-noreturn
|
||||
endif
|
||||
AM_CPPFLAGS = $(X_CFLAGS) $(pangocairo_CFLAGS) $(confuse_CFLAGS) $(xrandr_CFLAGS) $(xinerama_CFLAGS) $(AWESOME_CFLAGS) $(GTK_CFLAGS) $(imlib2_CFLAGS)
|
||||
AM_CPPFLAGS = $(pangocairo_CFLAGS) $(confuse_CFLAGS) $(AWESOME_CFLAGS) \
|
||||
$(GTK_CFLAGS) $(imlib2_CFLAGS) \
|
||||
$(xcb_CFLAGS) $(xcb_event_CFLAGS) \
|
||||
$(xcb_randr_CFLAGS) $(xcb_xinerama_CFLAGS) $(xcb_shape_CFLAGS) \
|
||||
$(xcb_aux_CFLAGS) $(xcb_atom_CFLAGS) $(xcb_keysyms_CFLAGS) \
|
||||
$(xcb_icccm_CFLAGS)
|
||||
|
||||
bin_PROGRAMS += awesome
|
||||
awesome_SOURCES = \
|
||||
|
@ -140,10 +145,14 @@ awesome_SOURCES = \
|
|||
rules.c rules.h \
|
||||
mouse.c mouse.h \
|
||||
widget.c widget.h \
|
||||
xcb_event_handler.c xcb_event_handler.h \
|
||||
ewmh.c ewmh.h
|
||||
awesome_SOURCES += $(LAYOUTS)
|
||||
awesome_SOURCES += $(WIDGETS)
|
||||
awesome_LDADD = $(X_LIBS) $(pangocairo_LIBS) $(confuse_LIBS) $(xrandr_LIBS) $(xinerama_LIBS) $(GTK_LIBS) $(imlib2_LIBS)
|
||||
awesome_LDADD = $(pangocairo_LIBS) $(confuse_LIBS) $(xcb_LIBS) $(xcb_event_LIBS) \
|
||||
$(xcb_randr_LIBS) $(xcb_xinerama_LIBS) $(xcb_shape_LIBS) $(xcb_aux_LIBS) \
|
||||
$(xcb_atom_LIBS) $(xcb_keysyms_LIBS) $(xcb_icccm_LIBS) \
|
||||
$(imlib2_LIBS) $(GTK_LIBS)
|
||||
|
||||
bin_PROGRAMS += awesome-client
|
||||
awesome_client_SOURCES = \
|
||||
|
@ -160,9 +169,10 @@ awesome_message_SOURCES = \
|
|||
common/version.h common/version.c \
|
||||
common/configopts.h common/configopts.c \
|
||||
common/xscreen.h common/xscreen.c \
|
||||
common/xutil.h common/xutil.c \
|
||||
awesome-message.c
|
||||
|
||||
awesome_message_LDADD = $(X_LIBS) $(pangocairo_LIBS) $(confuse_LIBS) $(xinerama_LIBS) $(GTK_LIBS) $(imlib2_LIBS)
|
||||
awesome_message_LDADD = $(xcb_LIBS) $(xcb_atom_LIBS) $(xcb_keysyms_LIBS) $(xcb_aux_LIBS) \
|
||||
$(pangocairo_LIBS) $(confuse_LIBS) $(xcb_xinerama_LIBS) $(imlib2_LIBS) $(GTK_LIBS)
|
||||
|
||||
bin_PROGRAMS += awesome-menu
|
||||
awesome_menu_SOURCES = \
|
||||
|
@ -173,8 +183,8 @@ awesome_menu_SOURCES = \
|
|||
common/configopts.h common/configopts.c \
|
||||
common/xutil.h common/xutil.c \
|
||||
awesome-menu.c
|
||||
|
||||
awesome_menu_LDADD = $(X_LIBS) $(pangocairo_LIBS) $(confuse_LIBS) $(xinerama_LIBS) $(GTK_LIBS) $(imlib2_LIBS)
|
||||
awesome_menu_LDADD = $(xcb_LIBS) $(xcb_atom_LIBS) $(xcb_keysyms_LIBS) $(xcb_aux_LIBS) \
|
||||
$(pangocairo_LIBS) $(confuse_LIBS) $(xcb_xinerama_LIBS) $(imlib2_LIBS) $(GTK_LIBS)
|
||||
|
||||
if HAVE_XMLTO
|
||||
if HAVE_ASCIIDOC
|
||||
|
|
171
awesome-menu.c
171
awesome-menu.c
|
@ -36,7 +36,12 @@
|
|||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <X11/Xutil.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_atom.h>
|
||||
#include <xcb/xcb_keysyms.h>
|
||||
|
||||
/* XKeysymToString() */
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
#include "common/swindow.h"
|
||||
#include "common/util.h"
|
||||
|
@ -47,7 +52,7 @@
|
|||
|
||||
#define PROGNAME "awesome-menu"
|
||||
|
||||
#define CLEANMASK(mask) (mask & ~(globalconf.numlockmask | LockMask))
|
||||
#define CLEANMASK(mask) (mask & ~(globalconf.numlockmask | XCB_MOD_MASK_LOCK))
|
||||
|
||||
/** awesome-menu run status */
|
||||
typedef enum
|
||||
|
@ -76,7 +81,7 @@ struct item_t
|
|||
/** Previous and next elems in item_t list */
|
||||
item_t *prev, *next;
|
||||
/** True if the item currently matches */
|
||||
Bool match;
|
||||
bool match;
|
||||
};
|
||||
|
||||
/** Destructor for item structure
|
||||
|
@ -94,8 +99,10 @@ DO_SLIST(item_t, item, item_delete)
|
|||
/** awesome-run global configuration structure */
|
||||
typedef struct
|
||||
{
|
||||
/** Display ref */
|
||||
Display *display;
|
||||
/** Connection ref */
|
||||
xcb_connection_t *connection;
|
||||
/** Default screen number */
|
||||
int default_screen;
|
||||
/** The window */
|
||||
SimpleWindow *sw;
|
||||
/** The draw contet */
|
||||
|
@ -202,11 +209,11 @@ config_parse(int screen, const char *confpatharg,
|
|||
&& (cfg_styles = cfg_getsec(cfg_screen, "styles")))
|
||||
{
|
||||
/* Grab default styles */
|
||||
draw_style_init(globalconf.display, DefaultScreen(globalconf.display),
|
||||
draw_style_init(globalconf.connection, globalconf.default_screen,
|
||||
cfg_getsec(cfg_styles, "normal"),
|
||||
&globalconf.styles.normal, NULL);
|
||||
|
||||
draw_style_init(globalconf.display, DefaultScreen(globalconf.display),
|
||||
draw_style_init(globalconf.connection, globalconf.default_screen,
|
||||
cfg_getsec(cfg_styles, "focus"),
|
||||
&globalconf.styles.focus, &globalconf.styles.normal);
|
||||
}
|
||||
|
@ -214,11 +221,11 @@ config_parse(int screen, const char *confpatharg,
|
|||
/* Now grab menu styles if any */
|
||||
if(cfg_menu_styles)
|
||||
{
|
||||
draw_style_init(globalconf.display, DefaultScreen(globalconf.display),
|
||||
draw_style_init(globalconf.connection, globalconf.default_screen,
|
||||
cfg_getsec(cfg_menu_styles, "normal"),
|
||||
&globalconf.styles.normal, NULL);
|
||||
|
||||
draw_style_init(globalconf.display, DefaultScreen(globalconf.display),
|
||||
draw_style_init(globalconf.connection, globalconf.default_screen,
|
||||
cfg_getsec(cfg_menu_styles, "focus"),
|
||||
&globalconf.styles.focus, &globalconf.styles.normal);
|
||||
}
|
||||
|
@ -252,7 +259,7 @@ get_last_word(char *text)
|
|||
* \param directory directory to look into
|
||||
* \return always true
|
||||
*/
|
||||
static Bool
|
||||
static bool
|
||||
item_list_fill_file(const char *directory)
|
||||
{
|
||||
char *cwd, *home, *user, *filename;
|
||||
|
@ -290,7 +297,7 @@ item_list_fill_file(const char *directory)
|
|||
else
|
||||
{
|
||||
p_delete(&user);
|
||||
return False;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -300,7 +307,7 @@ item_list_fill_file(const char *directory)
|
|||
if(!(dir = opendir(cwd)))
|
||||
{
|
||||
p_delete(&cwd);
|
||||
return False;
|
||||
return false;
|
||||
}
|
||||
|
||||
while((dirinfo = readdir(dir)))
|
||||
|
@ -332,11 +339,11 @@ item_list_fill_file(const char *directory)
|
|||
closedir(dir);
|
||||
p_delete(&cwd);
|
||||
|
||||
return True;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
complete(Bool reverse)
|
||||
complete(bool reverse)
|
||||
{
|
||||
int loop = 2;
|
||||
item_t *item = NULL;
|
||||
|
@ -390,16 +397,16 @@ compute_match(const char *word)
|
|||
|
||||
for(item = globalconf.items; item; item = item->next)
|
||||
if(!a_strncmp(word, item->data, a_strlen(word)))
|
||||
item->match = True;
|
||||
item->match = true;
|
||||
else
|
||||
item->match = False;
|
||||
item->match = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(a_strlen(globalconf.text))
|
||||
item_list_fill_file(NULL);
|
||||
for(item = globalconf.items; item; item = item->next)
|
||||
item->match = True;
|
||||
item->match = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -412,7 +419,7 @@ redraw(void)
|
|||
{
|
||||
item_t *item;
|
||||
area_t geometry = { 0, 0, 0, 0, NULL, NULL };
|
||||
Bool selected_item_is_drawn = False;
|
||||
bool selected_item_is_drawn = false;
|
||||
int len, prompt_len, x_of_previous_item;
|
||||
style_t style;
|
||||
|
||||
|
@ -424,7 +431,8 @@ redraw(void)
|
|||
draw_text(globalconf.ctx, geometry, AlignLeft,
|
||||
MARGIN, globalconf.prompt, globalconf.styles.focus);
|
||||
|
||||
len = MARGIN * 2 + draw_textwidth(globalconf.display, globalconf.styles.focus.font, globalconf.prompt);
|
||||
len = MARGIN * 2 + draw_textwidth(globalconf.connection, globalconf.default_screen,
|
||||
globalconf.styles.focus.font, globalconf.prompt);
|
||||
geometry.x += len;
|
||||
geometry.width -= len;
|
||||
}
|
||||
|
@ -432,7 +440,8 @@ redraw(void)
|
|||
draw_text(globalconf.ctx, geometry, AlignLeft,
|
||||
MARGIN, globalconf.text, globalconf.styles.normal);
|
||||
|
||||
len = MARGIN * 2 + MAX(draw_textwidth(globalconf.display, globalconf.styles.normal.font, globalconf.text),
|
||||
len = MARGIN * 2 + MAX(draw_textwidth(globalconf.connection, globalconf.default_screen,
|
||||
globalconf.styles.normal.font, globalconf.text),
|
||||
geometry.width / 20);
|
||||
geometry.x += len;
|
||||
geometry.width -= len;
|
||||
|
@ -442,13 +451,14 @@ redraw(void)
|
|||
if(item->match)
|
||||
{
|
||||
style = item == globalconf.item_selected ? globalconf.styles.focus : globalconf.styles.normal;
|
||||
len = MARGIN + draw_textwidth(globalconf.display, style.font, item->data);
|
||||
len = MARGIN + draw_textwidth(globalconf.connection, globalconf.default_screen,
|
||||
style.font, item->data);
|
||||
if(item == globalconf.item_selected)
|
||||
{
|
||||
if(len > geometry.width)
|
||||
break;
|
||||
else
|
||||
selected_item_is_drawn = True;
|
||||
selected_item_is_drawn = true;
|
||||
}
|
||||
draw_text(globalconf.ctx, geometry, AlignLeft,
|
||||
MARGIN / 2, item->data, style);
|
||||
|
@ -466,7 +476,8 @@ redraw(void)
|
|||
{
|
||||
style = item == globalconf.item_selected ? globalconf.styles.focus : globalconf.styles.normal;
|
||||
x_of_previous_item = geometry.x;
|
||||
geometry.width = MARGIN + draw_textwidth(globalconf.display, style.font, item->data);
|
||||
geometry.width = MARGIN + draw_textwidth(globalconf.connection, globalconf.default_screen,
|
||||
style.font, item->data);
|
||||
geometry.x -= geometry.width;
|
||||
|
||||
if(geometry.x < prompt_len)
|
||||
|
@ -480,31 +491,37 @@ redraw(void)
|
|||
{
|
||||
geometry.x = prompt_len;
|
||||
geometry.width = x_of_previous_item - prompt_len;
|
||||
draw_rectangle(globalconf.ctx, geometry, 1.0, True, globalconf.styles.normal.bg);
|
||||
draw_rectangle(globalconf.ctx, geometry, 1.0, true, globalconf.styles.normal.bg);
|
||||
}
|
||||
}
|
||||
else if(geometry.width)
|
||||
draw_rectangle(globalconf.ctx, geometry, 1.0, True, globalconf.styles.normal.bg);
|
||||
draw_rectangle(globalconf.ctx, geometry, 1.0, true, globalconf.styles.normal.bg);
|
||||
|
||||
simplewindow_refresh_drawable(globalconf.sw, DefaultScreen(globalconf.display));
|
||||
XSync(globalconf.display, False);
|
||||
simplewindow_refresh_drawable(globalconf.sw, globalconf.default_screen);
|
||||
xcb_aux_sync(globalconf.connection);
|
||||
}
|
||||
|
||||
/** Handle keypress event in awesome-menu.
|
||||
* \param e received XKeyEvent
|
||||
*/
|
||||
static void
|
||||
handle_kpress(XKeyEvent *e)
|
||||
handle_kpress(xcb_key_press_event_t *e)
|
||||
{
|
||||
char buf[32];
|
||||
KeySym ksym;
|
||||
char *buf;
|
||||
xcb_key_symbols_t *keysyms = xcb_key_symbols_alloc(globalconf.connection);
|
||||
xcb_keysym_t ksym;
|
||||
int num;
|
||||
ssize_t len;
|
||||
size_t text_dst_len;
|
||||
|
||||
len = a_strlen(globalconf.text);
|
||||
num = XLookupString(e, buf, sizeof(buf), &ksym, 0);
|
||||
if(e->state & ControlMask)
|
||||
/* TODO: check whether 'col' (last parameter) is correct */
|
||||
ksym = xcb_key_press_lookup_keysym(keysyms, e, 1);
|
||||
|
||||
/* TODO: remove this call in favor of XCB */
|
||||
buf = XKeysymToString(ksym);
|
||||
num = strlen(buf);
|
||||
if(e->state & XCB_MOD_MASK_CONTROL)
|
||||
switch(ksym)
|
||||
{
|
||||
default:
|
||||
|
@ -543,7 +560,7 @@ handle_kpress(XKeyEvent *e)
|
|||
}
|
||||
return;
|
||||
}
|
||||
else if(CLEANMASK(e->state) & Mod1Mask)
|
||||
else if(CLEANMASK(e->state) & XCB_MOD_MASK_1)
|
||||
switch(ksym)
|
||||
{
|
||||
default:
|
||||
|
@ -590,12 +607,12 @@ handle_kpress(XKeyEvent *e)
|
|||
break;
|
||||
case XK_ISO_Left_Tab:
|
||||
case XK_Left:
|
||||
complete(True);
|
||||
complete(true);
|
||||
redraw();
|
||||
break;
|
||||
case XK_Right:
|
||||
case XK_Tab:
|
||||
complete(False);
|
||||
complete(false);
|
||||
redraw();
|
||||
break;
|
||||
case XK_Escape:
|
||||
|
@ -638,7 +655,7 @@ getline(char ** buf, size_t* len, FILE* in)
|
|||
/** Fill the completion by reading on stdin.
|
||||
* \return true if something has been filled up, false otherwise.
|
||||
*/
|
||||
static Bool
|
||||
static bool
|
||||
item_list_fill_stdin(void)
|
||||
{
|
||||
char *buf = NULL;
|
||||
|
@ -646,12 +663,12 @@ item_list_fill_stdin(void)
|
|||
ssize_t line_len;
|
||||
|
||||
item_t *newitem;
|
||||
Bool has_entry = False;
|
||||
bool has_entry = false;
|
||||
|
||||
item_list_init(&globalconf.items);
|
||||
|
||||
if((line_len = getline(&buf, &len, stdin)) != -1)
|
||||
has_entry = True;
|
||||
has_entry = true;
|
||||
|
||||
if(has_entry)
|
||||
do
|
||||
|
@ -659,7 +676,7 @@ item_list_fill_stdin(void)
|
|||
buf[line_len - 1] = '\0';
|
||||
newitem = p_new(item_t, 1);
|
||||
newitem->data = a_strdup(buf);
|
||||
newitem->match = True;
|
||||
newitem->match = true;
|
||||
item_list_append(&globalconf.items, newitem);
|
||||
}
|
||||
while((line_len = getline(&buf, &len, stdin)) != -1);
|
||||
|
@ -676,11 +693,19 @@ static void
|
|||
keyboard_grab(void)
|
||||
{
|
||||
int i;
|
||||
xcb_grab_keyboard_reply_t *xgb = NULL;
|
||||
for(i = 1000; i; i--)
|
||||
{
|
||||
if(XGrabKeyboard(globalconf.display, DefaultRootWindow(globalconf.display), True,
|
||||
GrabModeAsync, GrabModeAsync, CurrentTime) == GrabSuccess)
|
||||
if((xgb = xcb_grab_keyboard_reply(globalconf.connection,
|
||||
xcb_grab_keyboard(globalconf.connection, true,
|
||||
xcb_aux_get_screen(globalconf.connection, globalconf.default_screen)->root,
|
||||
XCB_CURRENT_TIME, XCB_GRAB_MODE_ASYNC,
|
||||
XCB_GRAB_MODE_ASYNC),
|
||||
NULL)) != NULL)
|
||||
{
|
||||
p_delete(&xgb);
|
||||
break;
|
||||
}
|
||||
usleep(1000);
|
||||
}
|
||||
if(!i)
|
||||
|
@ -695,15 +720,14 @@ keyboard_grab(void)
|
|||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
XEvent ev;
|
||||
int opt, ret, x, y, i, screen = 0;
|
||||
xcb_generic_event_t *ev;
|
||||
int opt, ret, screen = 0;
|
||||
xcb_query_pointer_reply_t *xqp = NULL;
|
||||
char *configfile = NULL, *cmd;
|
||||
ssize_t len;
|
||||
const char *shell = getenv("SHELL");
|
||||
area_t geometry = { 0, 0, 0, 0, NULL, NULL };
|
||||
ScreensInfo *si;
|
||||
unsigned int ui;
|
||||
Window dummy;
|
||||
static struct option long_options[] =
|
||||
{
|
||||
{"help", 0, NULL, 'h'},
|
||||
|
@ -733,19 +757,24 @@ main(int argc, char **argv)
|
|||
if(argc - optind >= 1)
|
||||
globalconf.prompt = a_strdup(argv[optind]);
|
||||
|
||||
if(!(globalconf.display = XOpenDisplay(NULL)))
|
||||
globalconf.connection = xcb_connect(NULL, &globalconf.default_screen);
|
||||
if(xcb_connection_has_error(globalconf.connection))
|
||||
eprint("unable to open display");
|
||||
|
||||
/* Get the numlock mask */
|
||||
globalconf.numlockmask = xgetnumlockmask(globalconf.display);
|
||||
globalconf.numlockmask = xgetnumlockmask(globalconf.connection);
|
||||
|
||||
si = screensinfo_new(globalconf.display);
|
||||
si = screensinfo_new(globalconf.connection);
|
||||
if(si->xinerama_is_active)
|
||||
{
|
||||
if(XQueryPointer(globalconf.display, RootWindow(globalconf.display, DefaultScreen(globalconf.display)),
|
||||
&dummy, &dummy, &x, &y, &i, &i, &ui))
|
||||
if((xqp = xcb_query_pointer_reply(globalconf.connection,
|
||||
xcb_query_pointer(globalconf.connection,
|
||||
root_window(globalconf.connection,
|
||||
globalconf.default_screen)),
|
||||
NULL)) != NULL)
|
||||
{
|
||||
screen = screen_get_bycoord(si, 0, x, y);
|
||||
screen = screen_get_bycoord(si, 0, xqp->root_x, xqp->root_y);
|
||||
p_delete(&xqp);
|
||||
|
||||
geometry.x = si->geometry[screen].x;
|
||||
geometry.y = si->geometry[screen].y;
|
||||
|
@ -754,9 +783,9 @@ main(int argc, char **argv)
|
|||
}
|
||||
else
|
||||
{
|
||||
screen = DefaultScreen(globalconf.display);
|
||||
screen = globalconf.default_screen;
|
||||
if(!geometry.width)
|
||||
geometry.width = DisplayWidth(globalconf.display, DefaultScreen(globalconf.display));
|
||||
geometry.width = xcb_aux_get_screen(globalconf.connection, globalconf.default_screen)->width_in_pixels;
|
||||
}
|
||||
|
||||
if((ret = config_parse(screen, configfile, globalconf.prompt, &geometry)))
|
||||
|
@ -770,13 +799,15 @@ main(int argc, char **argv)
|
|||
screensinfo_delete(&si);
|
||||
|
||||
/* Create the window */
|
||||
globalconf.sw = simplewindow_new(globalconf.display, DefaultScreen(globalconf.display),
|
||||
globalconf.sw = simplewindow_new(globalconf.connection, globalconf.default_screen,
|
||||
geometry.x, geometry.y, geometry.width, geometry.height, 0);
|
||||
|
||||
XStoreName(globalconf.display, globalconf.sw->window, PROGNAME);
|
||||
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
|
||||
globalconf.sw->window, WM_NAME, STRING, 8,
|
||||
strlen(PROGNAME), PROGNAME);
|
||||
|
||||
/* Create the drawing context */
|
||||
globalconf.ctx = draw_context_new(globalconf.display, DefaultScreen(globalconf.display),
|
||||
globalconf.ctx = draw_context_new(globalconf.connection, globalconf.default_screen,
|
||||
geometry.width, geometry.height,
|
||||
globalconf.sw->drawable);
|
||||
|
||||
|
@ -804,26 +835,34 @@ main(int argc, char **argv)
|
|||
|
||||
redraw();
|
||||
|
||||
XMapRaised(globalconf.display, globalconf.sw->window);
|
||||
xutil_map_raised(globalconf.connection, globalconf.sw->window);
|
||||
|
||||
while(status == RUN)
|
||||
{
|
||||
XNextEvent(globalconf.display, &ev);
|
||||
switch(ev.type)
|
||||
while((ev = xcb_poll_for_event(globalconf.connection)))
|
||||
{
|
||||
case ButtonPress:
|
||||
/* Skip errors */
|
||||
if(ev->response_type == 0)
|
||||
continue;
|
||||
|
||||
switch(ev->response_type & 0x7f)
|
||||
{
|
||||
case XCB_BUTTON_PRESS:
|
||||
status = CANCEL;
|
||||
break;
|
||||
case KeyPress:
|
||||
handle_kpress(&ev.xkey);
|
||||
case XCB_KEY_PRESS:
|
||||
handle_kpress((xcb_key_press_event_t *) ev);
|
||||
break;
|
||||
case Expose:
|
||||
if(!ev.xexpose.count)
|
||||
simplewindow_refresh_drawable(globalconf.sw, DefaultScreen(globalconf.display));
|
||||
case XCB_EXPOSE:
|
||||
if(!((xcb_expose_event_t *) ev)->count)
|
||||
simplewindow_refresh_drawable(globalconf.sw, globalconf.default_screen);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
p_delete(&ev);
|
||||
}
|
||||
}
|
||||
|
||||
if(status != CANCEL)
|
||||
|
@ -845,7 +884,7 @@ main(int argc, char **argv)
|
|||
p_delete(&globalconf.text);
|
||||
draw_context_delete(&globalconf.ctx);
|
||||
simplewindow_delete(&globalconf.sw);
|
||||
XCloseDisplay(globalconf.display);
|
||||
xcb_disconnect(globalconf.connection);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -26,8 +26,11 @@
|
|||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_aux.h>
|
||||
#include <xcb/xcb_atom.h>
|
||||
|
||||
#include "common/swindow.h"
|
||||
#include "common/util.h"
|
||||
|
@ -37,7 +40,7 @@
|
|||
|
||||
#define PROGNAME "awesome-message"
|
||||
|
||||
static Bool running = True;
|
||||
static bool running = true;
|
||||
|
||||
/** Import awesome config file format */
|
||||
extern cfg_opt_t awesome_opts[];
|
||||
|
@ -46,7 +49,9 @@ extern cfg_opt_t awesome_opts[];
|
|||
typedef struct
|
||||
{
|
||||
/** Display ref */
|
||||
Display *display;
|
||||
xcb_connection_t *connection;
|
||||
/** Default screen number */
|
||||
int default_screen;
|
||||
/** Style */
|
||||
style_t style;
|
||||
} AwesomeMsgConf;
|
||||
|
@ -95,7 +100,7 @@ config_parse(int screen, const char *confpatharg)
|
|||
eprint("parsing configuration file failed, no screen section found\n");
|
||||
|
||||
/* style */
|
||||
draw_style_init(globalconf.display, DefaultScreen(globalconf.display),
|
||||
draw_style_init(globalconf.connection, globalconf.default_screen,
|
||||
cfg_getsec(cfg_getsec(cfg_screen, "styles"), "normal"),
|
||||
&globalconf.style, NULL);
|
||||
|
||||
|
@ -110,7 +115,7 @@ config_parse(int screen, const char *confpatharg)
|
|||
static void
|
||||
exit_on_signal(int sig __attribute__ ((unused)))
|
||||
{
|
||||
running = False;
|
||||
running = false;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -118,14 +123,13 @@ main(int argc, char **argv)
|
|||
{
|
||||
SimpleWindow *sw;
|
||||
DrawCtx *ctx;
|
||||
XEvent ev;
|
||||
xcb_generic_event_t *ev;
|
||||
area_t geometry = { 0, 0, 200, 50, NULL, NULL },
|
||||
icon_geometry = { -1, -1, -1, -1, NULL, NULL };
|
||||
int opt, i, x, y, ret, screen = 0, delay = 0;
|
||||
unsigned int ui;
|
||||
int opt, ret, screen = 0, delay = 0;
|
||||
xcb_query_pointer_reply_t *xqp = NULL;
|
||||
char *configfile = NULL;
|
||||
ScreensInfo *si;
|
||||
Window dummy;
|
||||
static struct option long_options[] =
|
||||
{
|
||||
{"help", 0, NULL, 'h'},
|
||||
|
@ -161,23 +165,31 @@ main(int argc, char **argv)
|
|||
if(argc - optind < 1)
|
||||
exit_help(EXIT_FAILURE);
|
||||
|
||||
if(!(globalconf.display = XOpenDisplay(NULL)))
|
||||
globalconf.connection = xcb_connect(NULL, &globalconf.default_screen);
|
||||
if(xcb_connection_has_error(globalconf.connection))
|
||||
eprint("unable to open display");
|
||||
|
||||
si = screensinfo_new(globalconf.display);
|
||||
si = screensinfo_new(globalconf.connection);
|
||||
if(si->xinerama_is_active)
|
||||
{
|
||||
if(XQueryPointer(globalconf.display, RootWindow(globalconf.display, DefaultScreen(globalconf.display)),
|
||||
&dummy, &dummy, &x, &y, &i, &i, &ui))
|
||||
screen = screen_get_bycoord(si, 0, x, y);
|
||||
if((xqp = xcb_query_pointer_reply(globalconf.connection,
|
||||
xcb_query_pointer(globalconf.connection,
|
||||
root_window(globalconf.connection,
|
||||
globalconf.default_screen)),
|
||||
NULL)) != NULL)
|
||||
{
|
||||
screen = screen_get_bycoord(si, 0, xqp->root_x, xqp->root_y);
|
||||
p_delete(&xqp);
|
||||
}
|
||||
}
|
||||
else
|
||||
screen = DefaultScreen(globalconf.display);
|
||||
screen = globalconf.default_screen;
|
||||
|
||||
if((ret = config_parse(screen, configfile)))
|
||||
return ret;
|
||||
|
||||
geometry.width = draw_textwidth(globalconf.display, globalconf.style.font, argv[optind]);
|
||||
geometry.width = draw_textwidth(globalconf.connection, globalconf.default_screen,
|
||||
globalconf.style.font, argv[optind]);
|
||||
geometry.height = globalconf.style.font->height * 1.5;
|
||||
|
||||
if(argc - optind >= 2)
|
||||
|
@ -190,12 +202,13 @@ main(int argc, char **argv)
|
|||
* ((double) globalconf.style.font->height / (double) icon_geometry.height);
|
||||
}
|
||||
|
||||
sw = simplewindow_new(globalconf.display, DefaultScreen(globalconf.display),
|
||||
sw = simplewindow_new(globalconf.connection, globalconf.default_screen,
|
||||
geometry.x, geometry.y, geometry.width, geometry.height, 0);
|
||||
|
||||
XStoreName(globalconf.display, sw->window, PROGNAME);
|
||||
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, sw->window,
|
||||
WM_NAME, STRING, 8, strlen(PROGNAME), PROGNAME);
|
||||
|
||||
ctx = draw_context_new(globalconf.display, DefaultScreen(globalconf.display),
|
||||
ctx = draw_context_new(globalconf.connection, globalconf.default_screen,
|
||||
geometry.width, geometry.height, sw->drawable);
|
||||
|
||||
geometry.x = geometry.y = 0;
|
||||
|
@ -207,36 +220,41 @@ main(int argc, char **argv)
|
|||
|
||||
p_delete(&ctx);
|
||||
|
||||
simplewindow_refresh_drawable(sw, DefaultScreen(globalconf.display));
|
||||
simplewindow_refresh_drawable(sw, globalconf.default_screen);
|
||||
|
||||
XMapRaised(globalconf.display, sw->window);
|
||||
XSync(globalconf.display, False);
|
||||
xutil_map_raised(globalconf.connection, sw->window);
|
||||
xcb_aux_sync(globalconf.connection);
|
||||
|
||||
signal(SIGALRM, &exit_on_signal);
|
||||
alarm(delay);
|
||||
|
||||
while(running)
|
||||
{
|
||||
if(XPending(globalconf.display))
|
||||
while((ev = xcb_poll_for_event(globalconf.connection)))
|
||||
{
|
||||
XNextEvent(globalconf.display, &ev);
|
||||
switch(ev.type)
|
||||
/* Skip errors */
|
||||
if(ev->response_type == 0)
|
||||
continue;
|
||||
|
||||
switch(ev->response_type & 0x7f)
|
||||
{
|
||||
case ButtonPress:
|
||||
case KeyPress:
|
||||
running = False;
|
||||
case Expose:
|
||||
simplewindow_refresh_drawable(sw, DefaultScreen(globalconf.display));
|
||||
case XCB_BUTTON_PRESS:
|
||||
case XCB_KEY_PRESS:
|
||||
running = false;
|
||||
case XCB_EXPOSE:
|
||||
simplewindow_refresh_drawable(sw, globalconf.default_screen);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
p_delete(&ev);
|
||||
}
|
||||
usleep(100000);
|
||||
}
|
||||
|
||||
simplewindow_delete(&sw);
|
||||
XCloseDisplay(globalconf.display);
|
||||
xcb_disconnect(globalconf.connection);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
390
awesome.c
390
awesome.c
|
@ -33,13 +33,14 @@
|
|||
#include <sys/un.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <X11/cursorfont.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xproto.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/extensions/shape.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include <alloca.h>
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/shape.h>
|
||||
#include <xcb/randr.h>
|
||||
#include <xcb/xcb_aux.h>
|
||||
#include <xcb/xcb_atom.h>
|
||||
#include <xcb/xcb_icccm.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "awesome.h"
|
||||
|
@ -52,53 +53,174 @@
|
|||
#include "client.h"
|
||||
#include "focus.h"
|
||||
#include "ewmh.h"
|
||||
#include "xcb_event_handler.h"
|
||||
#include "tag.h"
|
||||
#include "common/socket.h"
|
||||
#include "common/util.h"
|
||||
#include "common/version.h"
|
||||
#include "common/configopts.h"
|
||||
#include "common/xscreen.h"
|
||||
#include "common/xutil.h"
|
||||
|
||||
static int (*xerrorxlib) (Display *, XErrorEvent *);
|
||||
static Bool running = True;
|
||||
static bool running = true;
|
||||
|
||||
AwesomeConf globalconf;
|
||||
|
||||
/** Get geometry informations like XCB version, and also set 'x' and
|
||||
* 'y' parameter on its parent window like Xlib does
|
||||
*
|
||||
* TODO: improve round-trip time?
|
||||
*/
|
||||
static xcb_get_geometry_reply_t *
|
||||
x_get_geometry(xcb_connection_t *c, xcb_window_t w, xcb_get_geometry_reply_t *parent)
|
||||
{
|
||||
xcb_get_geometry_reply_t *win_geom;
|
||||
|
||||
win_geom = xcb_get_geometry_reply(c, xcb_get_geometry(c, w), NULL);
|
||||
|
||||
if(win_geom)
|
||||
return NULL;
|
||||
|
||||
/* Unlike XCB, Xlib set 'x' and 'y' as parent window position */
|
||||
win_geom->x = parent->x;
|
||||
win_geom->y = parent->y;
|
||||
|
||||
return win_geom;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
xcb_get_geometry_cookie_t geom;
|
||||
xcb_query_tree_cookie_t tree;
|
||||
} screen_win_t;
|
||||
|
||||
/** Scan X to find windows to manage
|
||||
*/
|
||||
static void
|
||||
scan()
|
||||
{
|
||||
unsigned int i, num;
|
||||
unsigned int i;
|
||||
int screen, real_screen;
|
||||
Window *wins = NULL, d1, d2;
|
||||
XWindowAttributes wa;
|
||||
xcb_window_t w;
|
||||
xcb_window_t *wins = NULL;
|
||||
xcb_query_tree_reply_t *r_query_tree;
|
||||
xcb_get_geometry_reply_t *parent_geom, *win_geom;
|
||||
xcb_get_window_attributes_reply_t *reply_win;
|
||||
xcb_get_window_attributes_cookie_t *cookies_win;
|
||||
const int screen_max = xcb_setup_roots_length (xcb_get_setup (globalconf.connection));
|
||||
screen_win_t *parents = alloca(sizeof(screen_win_t) * screen_max);
|
||||
|
||||
for(screen = 0; screen < ScreenCount(globalconf.display); screen++)
|
||||
for(screen = 0; screen < screen_max; screen++)
|
||||
{
|
||||
if(XQueryTree(globalconf.display, RootWindow(globalconf.display, screen), &d1, &d2, &wins, &num))
|
||||
for(i = 0; i < num; i++)
|
||||
/* XGetWindowAttributes return 1 on success */
|
||||
if(XGetWindowAttributes(globalconf.display, wins[i], &wa)
|
||||
&& !wa.override_redirect
|
||||
&& (wa.map_state == IsViewable || window_getstate(wins[i]) == IconicState))
|
||||
w = root_window(globalconf.connection, screen);
|
||||
|
||||
/* Get parent geometry informations, useful to get the real
|
||||
* coordinates of the window because Xlib set 'x' and 'y'
|
||||
* fields to the relative position within the parent window */
|
||||
parents[screen].geom = xcb_get_geometry(globalconf.connection, w);
|
||||
|
||||
/* Get the window tree */
|
||||
parents[screen].tree = xcb_query_tree_unchecked(globalconf.connection, w);
|
||||
}
|
||||
|
||||
for(screen = 0; screen < screen_max; screen++)
|
||||
{
|
||||
real_screen = screen_get_bycoord(globalconf.screens_info, screen, wa.x, wa.y);
|
||||
client_manage(wins[i], &wa, real_screen);
|
||||
parent_geom = xcb_get_geometry_reply (globalconf.connection,
|
||||
parents[screen].geom, NULL);
|
||||
|
||||
if(!parent_geom)
|
||||
continue;
|
||||
|
||||
r_query_tree = xcb_query_tree_reply(globalconf.connection,
|
||||
parents[screen].tree, NULL);
|
||||
|
||||
if(!r_query_tree)
|
||||
{
|
||||
p_delete(&parent_geom);
|
||||
continue;
|
||||
}
|
||||
if(wins)
|
||||
XFree(wins);
|
||||
|
||||
wins = xcb_query_tree_children(r_query_tree);
|
||||
|
||||
/* Store the answers of 'xcb_get_window_attributes' for all
|
||||
* child windows */
|
||||
cookies_win = p_new(xcb_get_window_attributes_cookie_t,
|
||||
r_query_tree->children_len);
|
||||
|
||||
/* Send all the requests at the same time */
|
||||
for(i = 0; i < r_query_tree->children_len; i++)
|
||||
cookies_win[i] = xcb_get_window_attributes(globalconf.connection, wins[i]);
|
||||
|
||||
/* Now process the answers */
|
||||
for(i = 0; i < r_query_tree->children_len; i++)
|
||||
{
|
||||
reply_win = xcb_get_window_attributes_reply(globalconf.connection,
|
||||
cookies_win[i],
|
||||
NULL);
|
||||
|
||||
if(reply_win && !reply_win->override_redirect &&
|
||||
(reply_win->map_state == XCB_MAP_STATE_VIEWABLE ||
|
||||
window_getstate(wins[i]) == XCB_WM_ICONIC_STATE))
|
||||
{
|
||||
/* TODO: should maybe be asynchronous */
|
||||
win_geom = x_get_geometry(globalconf.connection, w, parent_geom);
|
||||
if(!win_geom)
|
||||
{
|
||||
p_delete(&reply_win);
|
||||
continue;
|
||||
}
|
||||
|
||||
real_screen = screen_get_bycoord(globalconf.screens_info, screen, win_geom->x, win_geom->y);
|
||||
client_manage(wins[i], win_geom, real_screen);
|
||||
|
||||
/* win_geom is not useful anymore */
|
||||
p_delete(&win_geom);
|
||||
}
|
||||
|
||||
if(reply_win)
|
||||
p_delete(&reply_win);
|
||||
}
|
||||
|
||||
p_delete(&parent_geom);
|
||||
p_delete(&r_query_tree);
|
||||
p_delete(&cookies_win);
|
||||
}
|
||||
}
|
||||
|
||||
/** Equivalent to 'XCreateFontCursor()', error are handled by the
|
||||
* default current error handler
|
||||
* \param cursor_font type of cursor to use
|
||||
* \return allocated cursor font
|
||||
*/
|
||||
static xcb_cursor_t
|
||||
create_font_cursor(unsigned int cursor_font)
|
||||
{
|
||||
xcb_font_t font;
|
||||
xcb_cursor_t cursor;
|
||||
|
||||
/* Get the font for the cursor*/
|
||||
font = xcb_generate_id(globalconf.connection);
|
||||
xcb_open_font(globalconf.connection, font, strlen ("cursor"), "cursor");
|
||||
|
||||
cursor = xcb_generate_id(globalconf.connection);
|
||||
xcb_create_glyph_cursor (globalconf.connection, cursor, font, font,
|
||||
cursor_font, cursor_font + 1,
|
||||
0, 0, 0,
|
||||
0, 0, 0);
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
/** Startup Error handler to check if another window manager
|
||||
* is already running.
|
||||
* \param disp Display
|
||||
* \param ee Error event
|
||||
* \param data Additional optional parameters data
|
||||
* \param c X connection
|
||||
* \param error Error event
|
||||
*/
|
||||
static int __attribute__ ((noreturn))
|
||||
xerrorstart(Display * disp __attribute__ ((unused)),
|
||||
XErrorEvent * ee __attribute__ ((unused)))
|
||||
xerrorstart(void * data __attribute__ ((unused)),
|
||||
xcb_connection_t * c __attribute__ ((unused)),
|
||||
xcb_generic_error_t * error __attribute__ ((unused)))
|
||||
{
|
||||
eprint("another window manager is already running\n");
|
||||
}
|
||||
|
@ -111,13 +233,13 @@ xerrorstart(Display * disp __attribute__ ((unused)),
|
|||
void
|
||||
uicb_quit(int screen __attribute__ ((unused)), char *arg __attribute__ ((unused)))
|
||||
{
|
||||
running = False;
|
||||
running = false;
|
||||
}
|
||||
|
||||
static void
|
||||
exit_on_signal(int sig __attribute__ ((unused)))
|
||||
{
|
||||
running = False;
|
||||
running = false;
|
||||
}
|
||||
|
||||
/** \brief awesome xerror function
|
||||
|
@ -129,15 +251,39 @@ exit_on_signal(int sig __attribute__ ((unused)))
|
|||
* \return 0 if no error, or xerror's xlib return status
|
||||
*/
|
||||
static int
|
||||
xerror(Display *edpy, XErrorEvent *ee)
|
||||
xerror(void *data __attribute__ ((unused)),
|
||||
xcb_connection_t *c __attribute__ ((unused)),
|
||||
xcb_generic_error_t *e)
|
||||
{
|
||||
if(ee->error_code == BadWindow
|
||||
|| (ee->error_code == BadMatch && ee->request_code == X_SetInputFocus)
|
||||
|| (ee->error_code == BadValue && ee->request_code == X_KillClient)
|
||||
|| (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch))
|
||||
/*
|
||||
* Get the request code, taken from 'xcb-util/wm'. I can't figure
|
||||
* out how it works BTW, seems to get a byte in 'pad' member
|
||||
* (second byte in second element of the array)
|
||||
*/
|
||||
uint8_t request_code = (e->response_type == 0 ? *((uint8_t *) e + 10) : e->response_type);
|
||||
|
||||
if(e->error_code == BadWindow
|
||||
|| (e->error_code == BadMatch && request_code == XCB_SET_INPUT_FOCUS)
|
||||
|| (e->error_code == BadValue && request_code == XCB_KILL_CLIENT)
|
||||
|| (request_code == XCB_CONFIGURE_WINDOW && e->error_code == BadMatch))
|
||||
return 0;
|
||||
|
||||
warn("fatal error: request=%s, error=%s\n",
|
||||
x_label_request[request_code], x_label_error[e->error_code]);
|
||||
|
||||
/*
|
||||
* Xlib code was using default X error handler, namely
|
||||
* '_XDefaultError()', which displays more informations about the
|
||||
* error and also exit if 'error_code'' equals to
|
||||
* 'BadImplementation'
|
||||
*
|
||||
* TODO: display more informations about the error (like the Xlib
|
||||
* default error handler)
|
||||
*/
|
||||
if(e->error_code == BadImplementation)
|
||||
exit(1);
|
||||
|
||||
return 0;
|
||||
warn("fatal error: request code=%d, error code=%d\n", ee->request_code, ee->error_code);
|
||||
return xerrorxlib(edpy, ee); /* may call exit */
|
||||
}
|
||||
|
||||
/** Print help and exit(2) with given exit_code.
|
||||
|
@ -161,23 +307,21 @@ exit_help(int exit_code)
|
|||
* \param argv who knows
|
||||
* \return EXIT_SUCCESS I hope
|
||||
*/
|
||||
typedef void event_handler (XEvent *);
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
char buf[1024];
|
||||
const char *confpath = NULL;
|
||||
int r, xfd, e_dummy, csfd, shape_event, randr_event_base, i, screen, opt;
|
||||
int r, xfd, csfd, i, screen_nbr, opt;
|
||||
ssize_t cmdlen = 1;
|
||||
const xcb_query_extension_reply_t *shape_query, *randr_query;
|
||||
Statusbar *statusbar;
|
||||
fd_set rd;
|
||||
XEvent ev;
|
||||
Display * dpy;
|
||||
event_handler **handler;
|
||||
xcb_generic_event_t *ev;
|
||||
xcb_connection_t *conn;
|
||||
struct sockaddr_un *addr;
|
||||
Client *c;
|
||||
XSetWindowAttributes wa;
|
||||
Bool xsync = False, confcheck = False;
|
||||
bool confcheck = false;
|
||||
static struct option long_options[] =
|
||||
{
|
||||
{"help", 0, NULL, 'h'},
|
||||
|
@ -219,10 +363,7 @@ main(int argc, char *argv[])
|
|||
eprint("-c option requires a file name\n");
|
||||
break;
|
||||
case 'k':
|
||||
confcheck = True;
|
||||
break;
|
||||
case 's':
|
||||
xsync = True;
|
||||
confcheck = true;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -233,33 +374,48 @@ main(int argc, char *argv[])
|
|||
return config_check(confpath);
|
||||
|
||||
/* X stuff */
|
||||
if(!(dpy = XOpenDisplay(NULL)))
|
||||
conn = xcb_connect(NULL, &(globalconf.default_screen));
|
||||
if(xcb_connection_has_error(conn))
|
||||
eprint("cannot open display\n");
|
||||
|
||||
xfd = ConnectionNumber(dpy);
|
||||
xfd = xcb_get_file_descriptor(conn);
|
||||
|
||||
XSetErrorHandler(xerrorstart);
|
||||
for(screen = 0; screen < ScreenCount(dpy); screen++)
|
||||
/* this causes an error if some other window manager is running */
|
||||
XSelectInput(dpy, RootWindow(dpy, screen), SubstructureRedirectMask);
|
||||
/* Allocate a handler which will holds all errors and events */
|
||||
globalconf.evenths = xcb_alloc_event_handlers(conn);
|
||||
xcb_set_error_handler_catch_all(globalconf.evenths, xerrorstart, NULL);
|
||||
|
||||
/* need to XSync to validate errorhandler */
|
||||
XSync(dpy, False);
|
||||
XSetErrorHandler(NULL);
|
||||
xerrorxlib = XSetErrorHandler(xerror);
|
||||
XSync(dpy, False);
|
||||
for(screen_nbr = 0;
|
||||
screen_nbr < xcb_setup_roots_length(xcb_get_setup(conn));
|
||||
screen_nbr++)
|
||||
{
|
||||
/* this causes an error if some other window manager is
|
||||
* running */
|
||||
x_select_input(conn, root_window(conn, screen_nbr),
|
||||
XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT);
|
||||
}
|
||||
|
||||
/* need to xcb_flush to validate error handler */
|
||||
xcb_aux_sync(conn);
|
||||
|
||||
/* process all errors in the queue if any */
|
||||
xcb_poll_for_event_loop(globalconf.evenths);
|
||||
|
||||
/* set the default xerror handler */
|
||||
xcb_set_error_handler_catch_all(globalconf.evenths, xerror, NULL);
|
||||
|
||||
/* TODO
|
||||
if(xsync)
|
||||
XSynchronize(dpy, True);
|
||||
XSynchronize(dpy, true);
|
||||
*/
|
||||
|
||||
/* store display */
|
||||
globalconf.display = dpy;
|
||||
globalconf.connection = conn;
|
||||
|
||||
/* init EWMH atoms */
|
||||
ewmh_init_atoms();
|
||||
|
||||
/* init screens struct */
|
||||
globalconf.screens_info = screensinfo_new(dpy);
|
||||
globalconf.screens_info = screensinfo_new(conn);
|
||||
globalconf.screens = p_new(VirtScreen, globalconf.screens_info->nscreen);
|
||||
focus_add_client(NULL);
|
||||
|
||||
|
@ -267,72 +423,80 @@ main(int argc, char *argv[])
|
|||
config_parse(confpath);
|
||||
|
||||
/* init cursors */
|
||||
globalconf.cursor[CurNormal] = XCreateFontCursor(globalconf.display, XC_left_ptr);
|
||||
globalconf.cursor[CurResize] = XCreateFontCursor(globalconf.display, XC_sizing);
|
||||
globalconf.cursor[CurMove] = XCreateFontCursor(globalconf.display, XC_fleur);
|
||||
globalconf.cursor[CurNormal] = create_font_cursor(CURSOR_LEFT_PTR);
|
||||
globalconf.cursor[CurResize] = create_font_cursor(CURSOR_SIZING);
|
||||
globalconf.cursor[CurMove] = create_font_cursor(CURSOR_FLEUR);
|
||||
|
||||
/* for each virtual screen */
|
||||
for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
|
||||
for(screen_nbr = 0; screen_nbr < globalconf.screens_info->nscreen; screen_nbr++)
|
||||
{
|
||||
/* view at least one tag */
|
||||
tag_view(globalconf.screens[screen].tags, True);
|
||||
tag_view(globalconf.screens[screen_nbr].tags, true);
|
||||
|
||||
for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next)
|
||||
for(statusbar = globalconf.screens[screen_nbr].statusbar; statusbar; statusbar = statusbar->next)
|
||||
statusbar_init(statusbar);
|
||||
}
|
||||
|
||||
/* select for events */
|
||||
wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask
|
||||
| EnterWindowMask | LeaveWindowMask | StructureNotifyMask;
|
||||
wa.cursor = globalconf.cursor[CurNormal];
|
||||
const uint32_t change_win_vals[] =
|
||||
{
|
||||
XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY
|
||||
| XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW
|
||||
| XCB_EVENT_MASK_STRUCTURE_NOTIFY,
|
||||
globalconf.cursor[CurNormal]
|
||||
};
|
||||
|
||||
/* do this only for real screen */
|
||||
for(screen = 0; screen < ScreenCount(dpy); screen++)
|
||||
for(screen_nbr = 0;
|
||||
screen_nbr < xcb_setup_roots_length(xcb_get_setup(conn));
|
||||
screen_nbr++)
|
||||
{
|
||||
XChangeWindowAttributes(globalconf.display,
|
||||
RootWindow(globalconf.display, screen),
|
||||
CWEventMask | CWCursor, &wa);
|
||||
XSelectInput(globalconf.display,
|
||||
RootWindow(globalconf.display, screen),
|
||||
wa.event_mask);
|
||||
ewmh_set_supported_hints(screen);
|
||||
xcb_change_window_attributes(globalconf.connection,
|
||||
root_window(globalconf.connection, screen_nbr),
|
||||
XCB_CW_EVENT_MASK | XCB_CW_CURSOR,
|
||||
change_win_vals);
|
||||
x_select_input(globalconf.connection,
|
||||
root_window(globalconf.connection, screen_nbr),
|
||||
change_win_vals[0]);
|
||||
ewmh_set_supported_hints(screen_nbr);
|
||||
/* call this to at least grab root window clicks */
|
||||
window_root_grabbuttons(screen);
|
||||
window_root_grabkeys(screen);
|
||||
window_root_grabbuttons(screen_nbr);
|
||||
window_root_grabkeys(screen_nbr);
|
||||
}
|
||||
|
||||
/* scan existing windows */
|
||||
scan();
|
||||
|
||||
handler = p_new(event_handler *, LASTEvent);
|
||||
handler[ButtonPress] = event_handle_buttonpress;
|
||||
handler[ConfigureRequest] = event_handle_configurerequest;
|
||||
handler[ConfigureNotify] = event_handle_configurenotify;
|
||||
handler[DestroyNotify] = event_handle_destroynotify;
|
||||
handler[EnterNotify] = event_handle_enternotify;
|
||||
handler[Expose] = event_handle_expose;
|
||||
handler[KeyPress] = event_handle_keypress;
|
||||
handler[MappingNotify] = event_handle_mappingnotify;
|
||||
handler[MapRequest] = event_handle_maprequest;
|
||||
handler[PropertyNotify] = event_handle_propertynotify;
|
||||
handler[UnmapNotify] = event_handle_unmapnotify;
|
||||
handler[ClientMessage] = event_handle_clientmessage;
|
||||
/* process all errors in the queue if any */
|
||||
xcb_poll_for_event_loop(globalconf.evenths);
|
||||
|
||||
set_button_press_event_handler(globalconf.evenths, event_handle_buttonpress, NULL);
|
||||
set_configure_request_event_handler(globalconf.evenths, event_handle_configurerequest, NULL);
|
||||
set_configure_notify_event_handler(globalconf.evenths, event_handle_configurenotify, NULL);
|
||||
set_destroy_notify_event_handler(globalconf.evenths, event_handle_destroynotify, NULL);
|
||||
set_enter_notify_event_handler(globalconf.evenths, event_handle_enternotify, NULL);
|
||||
set_expose_event_handler(globalconf.evenths, event_handle_expose, NULL);
|
||||
set_key_press_event_handler(globalconf.evenths, event_handle_keypress, NULL);
|
||||
set_mapping_notify_event_handler(globalconf.evenths, event_handle_mappingnotify, NULL);
|
||||
set_map_request_event_handler(globalconf.evenths, event_handle_maprequest, NULL);
|
||||
set_property_notify_event_handler(globalconf.evenths, event_handle_propertynotify, NULL);
|
||||
set_unmap_notify_event_handler(globalconf.evenths, event_handle_unmapnotify, NULL);
|
||||
set_client_message_event_handler(globalconf.evenths, event_handle_clientmessage, NULL);
|
||||
|
||||
/* check for shape extension */
|
||||
if((globalconf.have_shape = XShapeQueryExtension(dpy, &shape_event, &e_dummy)))
|
||||
{
|
||||
p_realloc(&handler, shape_event + 1);
|
||||
handler[shape_event] = event_handle_shape;
|
||||
}
|
||||
shape_query = xcb_get_extension_data(conn, &xcb_shape_id);
|
||||
if((globalconf.have_shape = shape_query->present))
|
||||
xcb_set_event_handler(globalconf.evenths, (shape_query->first_event + XCB_SHAPE_NOTIFY),
|
||||
(xcb_generic_event_handler_t) event_handle_shape, NULL);
|
||||
|
||||
/* check for randr extension */
|
||||
if((globalconf.have_randr = XRRQueryExtension(dpy, &randr_event_base, &e_dummy)))
|
||||
{
|
||||
p_realloc(&handler, randr_event_base + RRScreenChangeNotify + 1);
|
||||
handler[randr_event_base + RRScreenChangeNotify] = event_handle_randr_screen_change_notify;
|
||||
}
|
||||
randr_query = xcb_get_extension_data(conn, &xcb_randr_id);
|
||||
if((globalconf.have_randr = randr_query->present))
|
||||
xcb_set_event_handler(globalconf.evenths, (randr_query->first_event + XCB_RANDR_SCREEN_CHANGE_NOTIFY),
|
||||
(xcb_generic_event_handler_t) event_handle_randr_screen_change_notify,
|
||||
NULL);
|
||||
|
||||
XSync(dpy, False);
|
||||
xcb_aux_sync(conn);
|
||||
|
||||
/* get socket fd */
|
||||
csfd = socket_getclient();
|
||||
|
@ -397,23 +561,21 @@ main(int argc, char *argv[])
|
|||
* are available and select() won't tell us, so let's check
|
||||
* with XPending() again.
|
||||
*/
|
||||
while(XPending(dpy))
|
||||
while((ev = xcb_poll_for_event(conn)))
|
||||
{
|
||||
while(XPending(dpy))
|
||||
do
|
||||
{
|
||||
XNextEvent(dpy, &ev);
|
||||
if(handler[ev.type])
|
||||
handler[ev.type](&ev);
|
||||
xcb_handle_event(globalconf.evenths, ev);
|
||||
|
||||
/* need to resync */
|
||||
XSync(dpy, False);
|
||||
}
|
||||
xcb_aux_sync(conn);
|
||||
} while((ev = xcb_poll_for_event(conn)));
|
||||
|
||||
statusbar_refresh();
|
||||
layout_refresh();
|
||||
|
||||
/* need to resync */
|
||||
XSync(dpy, False);
|
||||
xcb_aux_sync(conn);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -428,9 +590,9 @@ main(int argc, char *argv[])
|
|||
for(c = globalconf.clients; c; c = c->next)
|
||||
client_unban(c);
|
||||
|
||||
XSync(globalconf.display, False);
|
||||
xcb_aux_sync(globalconf.connection);
|
||||
|
||||
XCloseDisplay(dpy);
|
||||
xcb_disconnect(conn);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
448
client.c
448
client.c
|
@ -20,8 +20,12 @@
|
|||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/extensions/shape.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_aux.h>
|
||||
#include <xcb/xcb_atom.h>
|
||||
#include <xcb/shape.h>
|
||||
|
||||
#include "client.h"
|
||||
#include "tag.h"
|
||||
|
@ -45,28 +49,28 @@ extern AwesomeConf globalconf;
|
|||
* \param screen Screen ID
|
||||
* \return true if client had property
|
||||
*/
|
||||
static Bool
|
||||
static bool
|
||||
client_loadprops(Client * c, int screen)
|
||||
{
|
||||
int i, ntags = 0;
|
||||
Tag *tag;
|
||||
char *prop;
|
||||
Bool result = False;
|
||||
bool result = false;
|
||||
|
||||
for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
|
||||
ntags++;
|
||||
|
||||
prop = p_new(char, ntags + 3);
|
||||
|
||||
if(xgettextprop(globalconf.display, c->win,
|
||||
XInternAtom(globalconf.display, "_AWESOME_PROPERTIES", False),
|
||||
if(xgettextprop(globalconf.connection, c->win,
|
||||
x_intern_atom(globalconf.connection, "_AWESOME_PROPERTIES"),
|
||||
prop, ntags + 3))
|
||||
{
|
||||
for(i = 0, tag = globalconf.screens[screen].tags; tag && i < ntags && prop[i]; i++, tag = tag->next)
|
||||
if(prop[i] == '1')
|
||||
{
|
||||
tag_client(c, tag);
|
||||
result = True;
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
untag_client(c, tag);
|
||||
|
@ -83,21 +87,21 @@ client_loadprops(Client * c, int screen)
|
|||
/** Check if client supports protocol WM_DELETE_WINDOW
|
||||
* \param disp the display
|
||||
* \param win the Window
|
||||
* \return True if client has WM_DELETE_WINDOW
|
||||
* \return true if client has WM_DELETE_WINDOW
|
||||
*/
|
||||
static Bool
|
||||
client_isprotodel(Display *disp, Window win)
|
||||
static bool
|
||||
client_isprotodel(xcb_connection_t *c, xcb_window_t win)
|
||||
{
|
||||
int i, n;
|
||||
Atom *protocols;
|
||||
Bool ret = False;
|
||||
uint32_t i, n;
|
||||
xcb_atom_t *protocols;
|
||||
bool ret = false;
|
||||
|
||||
if(XGetWMProtocols(disp, win, &protocols, &n))
|
||||
if(xcb_get_wm_protocols(c, win, &n, &protocols))
|
||||
{
|
||||
for(i = 0; !ret && i < n; i++)
|
||||
if(protocols[i] == XInternAtom(disp, "WM_DELETE_WINDOW", False))
|
||||
ret = True;
|
||||
XFree(protocols);
|
||||
if(protocols[i] == x_intern_atom(c, "WM_DELETE_WINDOW"))
|
||||
ret = true;
|
||||
p_delete(&protocols);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -108,7 +112,7 @@ client_isprotodel(Display *disp, Window win)
|
|||
* \return client
|
||||
*/
|
||||
Client *
|
||||
client_get_bywin(Client *list, Window w)
|
||||
client_get_bywin(Client *list, xcb_window_t w)
|
||||
{
|
||||
Client *c;
|
||||
|
||||
|
@ -139,10 +143,10 @@ client_get_byname(Client *list, char *name)
|
|||
void
|
||||
client_updatetitle(Client *c)
|
||||
{
|
||||
if(!xgettextprop(globalconf.display, c->win,
|
||||
XInternAtom(globalconf.display, "_NET_WM_NAME", False), c->name, sizeof(c->name)))
|
||||
xgettextprop(globalconf.display, c->win,
|
||||
XInternAtom(globalconf.display, "WM_NAME", False), c->name, sizeof(c->name));
|
||||
if(!xgettextprop(globalconf.connection, c->win,
|
||||
x_intern_atom(globalconf.connection, "_NET_WM_NAME"), c->name, sizeof(c->name)))
|
||||
xgettextprop(globalconf.connection, c->win,
|
||||
x_intern_atom(globalconf.connection, "WM_NAME"), c->name, sizeof(c->name));
|
||||
|
||||
titlebar_draw(c);
|
||||
|
||||
|
@ -157,8 +161,8 @@ client_unfocus(Client *c)
|
|||
else if(globalconf.screens[c->screen].opacity_focused != -1)
|
||||
window_settrans(c->win, -1);
|
||||
focus_add_client(NULL);
|
||||
XSetWindowBorder(globalconf.display, c->win,
|
||||
globalconf.screens[c->screen].styles.normal.border.pixel);
|
||||
xcb_change_window_attributes(globalconf.connection, c->win, XCB_CW_BORDER_PIXEL,
|
||||
&globalconf.screens[c->screen].styles.normal.border.pixel);
|
||||
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
||||
titlebar_draw(c);
|
||||
}
|
||||
|
@ -171,10 +175,10 @@ client_ban(Client *c)
|
|||
{
|
||||
if(globalconf.focus->client == c)
|
||||
client_unfocus(c);
|
||||
XUnmapWindow(globalconf.display, c->win);
|
||||
window_setstate(c->win, IconicState);
|
||||
xcb_unmap_window(globalconf.connection, c->win);
|
||||
window_setstate(c->win, XCB_WM_ICONIC_STATE);
|
||||
if(c->titlebar.position && c->titlebar.sw)
|
||||
XUnmapWindow(globalconf.display, c->titlebar.sw->window);
|
||||
xcb_unmap_window(globalconf.connection, c->titlebar.sw->window);
|
||||
}
|
||||
|
||||
/** Give focus to client, or to first client if c is NULL
|
||||
|
@ -183,8 +187,8 @@ client_ban(Client *c)
|
|||
* \param raise raise window if true
|
||||
* \return true if a window (even root) has received focus, false otherwise
|
||||
*/
|
||||
Bool
|
||||
client_focus(Client *c, int screen, Bool raise)
|
||||
bool
|
||||
client_focus(Client *c, int screen, bool raise)
|
||||
{
|
||||
int phys_screen;
|
||||
|
||||
|
@ -196,7 +200,7 @@ client_focus(Client *c, int screen, Bool raise)
|
|||
|
||||
/* if c is already the focused window, then stop */
|
||||
if(c == globalconf.focus->client)
|
||||
return False;
|
||||
return false;
|
||||
|
||||
/* unfocus current selected client */
|
||||
if(globalconf.focus->client)
|
||||
|
@ -212,10 +216,11 @@ client_focus(Client *c, int screen, Bool raise)
|
|||
window_settrans(c->win, globalconf.screens[c->screen].opacity_focused);
|
||||
else if(globalconf.screens[c->screen].opacity_unfocused != -1)
|
||||
window_settrans(c->win, -1);
|
||||
XSetWindowBorder(globalconf.display, c->win,
|
||||
globalconf.screens[screen].styles.focus.border.pixel);
|
||||
xcb_change_window_attributes(globalconf.connection, c->win, XCB_CW_BORDER_PIXEL,
|
||||
&globalconf.screens[screen].styles.focus.border.pixel);
|
||||
titlebar_draw(c);
|
||||
XSetInputFocus(globalconf.display, c->win, RevertToPointerRoot, CurrentTime);
|
||||
xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
|
||||
c->win, XCB_CURRENT_TIME);
|
||||
if(raise)
|
||||
client_stack(c);
|
||||
/* since we're dropping EnterWindow events and sometimes the window
|
||||
|
@ -226,27 +231,28 @@ client_focus(Client *c, int screen, Bool raise)
|
|||
else
|
||||
{
|
||||
phys_screen = screen_virttophys(screen);
|
||||
XSetInputFocus(globalconf.display,
|
||||
RootWindow(globalconf.display, phys_screen),
|
||||
RevertToPointerRoot, CurrentTime);
|
||||
xcb_set_input_focus(globalconf.connection,
|
||||
XCB_INPUT_FOCUS_POINTER_ROOT,
|
||||
root_window(globalconf.connection, phys_screen),
|
||||
XCB_CURRENT_TIME);
|
||||
}
|
||||
|
||||
ewmh_update_net_active_window(phys_screen);
|
||||
widget_invalidate_cache(screen, WIDGET_CACHE_CLIENTS);
|
||||
|
||||
return True;
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
client_stack(Client *c)
|
||||
{
|
||||
XWindowChanges wc;
|
||||
uint32_t config_win_vals[2];
|
||||
Client *client;
|
||||
unsigned int layer;
|
||||
Layer maxlayer = LAYER_FULLSCREEN;
|
||||
|
||||
wc.stack_mode = Above;
|
||||
wc.sibling = None;
|
||||
config_win_vals[0] = XCB_NONE;
|
||||
config_win_vals[1] = XCB_STACK_MODE_ABOVE;
|
||||
|
||||
for(layer = 0; layer < maxlayer; layer++)
|
||||
{
|
||||
|
@ -256,24 +262,31 @@ client_stack(Client *c)
|
|||
{
|
||||
if(client->titlebar.position && client->titlebar.sw)
|
||||
{
|
||||
XConfigureWindow(globalconf.display, client->titlebar.sw->window,
|
||||
CWSibling | CWStackMode, &wc);
|
||||
wc.sibling = client->titlebar.sw->window;
|
||||
xcb_configure_window(globalconf.connection,
|
||||
client->titlebar.sw->window,
|
||||
XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
|
||||
config_win_vals);
|
||||
config_win_vals[0] = client->titlebar.sw->window;
|
||||
}
|
||||
XConfigureWindow(globalconf.display, client->win, CWSibling | CWStackMode, &wc);
|
||||
wc.sibling = client->win;
|
||||
xcb_configure_window(globalconf.connection, client->win,
|
||||
XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
|
||||
config_win_vals);
|
||||
config_win_vals[0] = client->win;
|
||||
}
|
||||
}
|
||||
if(c->layer == layer)
|
||||
{
|
||||
if(c->titlebar.position && c->titlebar.sw)
|
||||
{
|
||||
XConfigureWindow(globalconf.display, c->titlebar.sw->window,
|
||||
CWSibling | CWStackMode, &wc);
|
||||
wc.sibling = c->titlebar.sw->window;
|
||||
xcb_configure_window(globalconf.connection, c->titlebar.sw->window,
|
||||
XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
|
||||
config_win_vals);
|
||||
config_win_vals[0] = c->titlebar.sw->window;
|
||||
}
|
||||
XConfigureWindow(globalconf.display, c->win, CWSibling | CWStackMode, &wc);
|
||||
wc.sibling = c->win;
|
||||
xcb_configure_window(globalconf.connection, c->win,
|
||||
XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
|
||||
config_win_vals);
|
||||
config_win_vals[0] = c->win;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -284,22 +297,22 @@ client_stack(Client *c)
|
|||
* \param screen Screen ID
|
||||
*/
|
||||
void
|
||||
client_manage(Window w, XWindowAttributes *wa, int screen)
|
||||
client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wa, int screen)
|
||||
{
|
||||
Client *c, *t = NULL;
|
||||
Window trans;
|
||||
Bool rettrans, retloadprops;
|
||||
XWindowChanges wc;
|
||||
xcb_window_t trans;
|
||||
bool rettrans, retloadprops;
|
||||
uint32_t config_win_val;
|
||||
Tag *tag;
|
||||
Rule *rule;
|
||||
long flags;
|
||||
xcb_size_hints_t *u_size_hints;
|
||||
|
||||
c = p_new(Client, 1);
|
||||
|
||||
c->screen = screen_get_bycoord(globalconf.screens_info, screen, wa->x, wa->y);
|
||||
|
||||
if(globalconf.screens_info->xinerama_is_active)
|
||||
c->phys_screen = DefaultScreen(globalconf.display);
|
||||
c->phys_screen = globalconf.default_screen;
|
||||
else
|
||||
c->phys_screen = c->screen;
|
||||
|
||||
|
@ -310,13 +323,15 @@ client_manage(Window w, XWindowAttributes *wa, int screen)
|
|||
c->geometry.width = c->f_geometry.width = c->m_geometry.width = wa->width;
|
||||
c->geometry.height = c->f_geometry.height = c->m_geometry.height = wa->height;
|
||||
c->oldborder = wa->border_width;
|
||||
c->newcomer = True;
|
||||
c->newcomer = true;
|
||||
c->layer = c->oldlayer = LAYER_TILE;
|
||||
|
||||
/* Set windows borders */
|
||||
wc.border_width = c->border = globalconf.screens[screen].borderpx;
|
||||
XConfigureWindow(globalconf.display, w, CWBorderWidth, &wc);
|
||||
XSetWindowBorder(globalconf.display, w, c->border);
|
||||
config_win_val = c->border = globalconf.screens[screen].borderpx;
|
||||
xcb_configure_window(globalconf.connection, w, XCB_CONFIG_WINDOW_BORDER_WIDTH,
|
||||
&config_win_val);
|
||||
xcb_configure_window(globalconf.connection, w, XCB_CONFIG_WINDOW_STACK_MODE,
|
||||
&config_win_val);
|
||||
/* propagates border_width, if size doesn't change */
|
||||
window_configure(c->win, c->geometry, c->border);
|
||||
|
||||
|
@ -324,12 +339,12 @@ client_manage(Window w, XWindowAttributes *wa, int screen)
|
|||
client_updatetitle(c);
|
||||
|
||||
/* update hints */
|
||||
flags = client_updatesizehints(c);
|
||||
u_size_hints = client_updatesizehints(c);
|
||||
client_updatewmhints(c);
|
||||
|
||||
/* Try to load props if any */
|
||||
if(!(retloadprops = client_loadprops(c, screen)))
|
||||
move_client_to_screen(c, screen, True);
|
||||
move_client_to_screen(c, screen, true);
|
||||
|
||||
/* Then check clients hints */
|
||||
ewmh_check_client_hints(c);
|
||||
|
@ -344,7 +359,7 @@ client_manage(Window w, XWindowAttributes *wa, int screen)
|
|||
if(!retloadprops && rule)
|
||||
{
|
||||
if(rule->screen != RULE_NOSCREEN)
|
||||
move_client_to_screen(c, rule->screen, True);
|
||||
move_client_to_screen(c, rule->screen, true);
|
||||
tag_client_with_rule(c, rule);
|
||||
|
||||
switch(rule->isfloating)
|
||||
|
@ -352,10 +367,10 @@ client_manage(Window w, XWindowAttributes *wa, int screen)
|
|||
case Maybe:
|
||||
break;
|
||||
case Yes:
|
||||
client_setfloating(c, True, c->layer != LAYER_TILE ? c->layer : LAYER_FLOAT);
|
||||
client_setfloating(c, true, c->layer != LAYER_TILE ? c->layer : LAYER_FLOAT);
|
||||
break;
|
||||
case No:
|
||||
client_setfloating(c, False, LAYER_TILE);
|
||||
client_setfloating(c, false, LAYER_TILE);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -363,10 +378,8 @@ client_manage(Window w, XWindowAttributes *wa, int screen)
|
|||
window_settrans(c->win, rule->opacity);
|
||||
}
|
||||
|
||||
/* check for transient and set tags like its parent,
|
||||
* XGetTransientForHint returns 1 on success
|
||||
*/
|
||||
if((rettrans = XGetTransientForHint(globalconf.display, w, &trans))
|
||||
/* check for transient and set tags like its parent */
|
||||
if((rettrans = x_get_transient_for_hint(globalconf.connection, w, &trans))
|
||||
&& (t = client_get_bywin(globalconf.clients, trans)))
|
||||
for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
|
||||
if(is_client_tagged(t, tag))
|
||||
|
@ -374,7 +387,7 @@ client_manage(Window w, XWindowAttributes *wa, int screen)
|
|||
|
||||
/* should be floating if transsient or fixed */
|
||||
if(rettrans || c->isfixed)
|
||||
client_setfloating(c, True, c->layer != LAYER_TILE ? c->layer : LAYER_FLOAT);
|
||||
client_setfloating(c, true, c->layer != LAYER_TILE ? c->layer : LAYER_FLOAT);
|
||||
|
||||
/* titlebar init */
|
||||
if(rule && rule->titlebar.position != Auto)
|
||||
|
@ -382,23 +395,27 @@ client_manage(Window w, XWindowAttributes *wa, int screen)
|
|||
|
||||
titlebar_init(c);
|
||||
|
||||
if(!retloadprops && !(flags & (USPosition | PPosition)))
|
||||
if(!retloadprops
|
||||
&& u_size_hints
|
||||
&& !(xcb_size_hints_is_us_position(u_size_hints) | xcb_size_hints_is_p_position(u_size_hints)))
|
||||
{
|
||||
if(c->isfloating && !c->ismax)
|
||||
client_resize(c, globalconf.screens[c->screen].floating_placement(c), False);
|
||||
client_resize(c, globalconf.screens[c->screen].floating_placement(c), false);
|
||||
else
|
||||
c->f_geometry = globalconf.screens[c->screen].floating_placement(c);
|
||||
|
||||
xcb_free_size_hints(u_size_hints);
|
||||
}
|
||||
|
||||
/* update titlebar with real floating info now */
|
||||
titlebar_update_geometry_floating(c);
|
||||
|
||||
XSelectInput(globalconf.display, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
|
||||
x_select_input(globalconf.connection, w, XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_PROPERTY_CHANGE | XCB_EVENT_MASK_ENTER_WINDOW);
|
||||
|
||||
/* handle xshape */
|
||||
if(globalconf.have_shape)
|
||||
{
|
||||
XShapeSelectInput(globalconf.display, w, ShapeNotifyMask);
|
||||
xcb_shape_select_input(globalconf.connection, w, true);
|
||||
window_setshape(c->win, c->phys_screen);
|
||||
}
|
||||
|
||||
|
@ -480,16 +497,15 @@ client_geometry_hints(Client *c, area_t geometry)
|
|||
* \param c client to resize
|
||||
* \param geometry new window geometry
|
||||
* \param hints use resize hints
|
||||
* \param return True if resize has been done
|
||||
* \param return true if resize has been done
|
||||
*/
|
||||
Bool
|
||||
client_resize(Client *c, area_t geometry, Bool hints)
|
||||
bool
|
||||
client_resize(Client *c, area_t geometry, bool hints)
|
||||
{
|
||||
int new_screen;
|
||||
area_t area;
|
||||
XWindowChanges wc;
|
||||
Layout *layout = layout_get_current(c->screen);
|
||||
Bool resized = False;
|
||||
bool resized = false;
|
||||
|
||||
if(!c->ismoving && !c->isfloating && layout->arrange != layout_floating)
|
||||
{
|
||||
|
@ -497,11 +513,15 @@ client_resize(Client *c, area_t geometry, Bool hints)
|
|||
geometry = titlebar_geometry_remove(&c->titlebar, geometry);
|
||||
}
|
||||
|
||||
/* Values to configure a window is an array where values are
|
||||
* stored according to 'value_mask' */
|
||||
uint32_t values[5];
|
||||
|
||||
if(hints)
|
||||
geometry = client_geometry_hints(c, geometry);
|
||||
|
||||
if(geometry.width <= 0 || geometry.height <= 0)
|
||||
return False;
|
||||
return false;
|
||||
|
||||
/* offscreen appearance fixes */
|
||||
area = get_display_area(c->phys_screen, NULL,
|
||||
|
@ -522,11 +542,11 @@ client_resize(Client *c, area_t geometry, Bool hints)
|
|||
new_screen =
|
||||
screen_get_bycoord(globalconf.screens_info, c->screen, geometry.x, geometry.y);
|
||||
|
||||
c->geometry.x = wc.x = geometry.x;
|
||||
c->geometry.width = wc.width = geometry.width;
|
||||
c->geometry.y = wc.y = geometry.y;
|
||||
c->geometry.height = wc.height = geometry.height;
|
||||
wc.border_width = c->border;
|
||||
c->geometry.x = values[0] = geometry.x;
|
||||
c->geometry.width = values[2] = geometry.width;
|
||||
c->geometry.y = values[1] = geometry.y;
|
||||
c->geometry.height = values[3] = geometry.height;
|
||||
values[4] = c->border;
|
||||
|
||||
/* save the floating geometry if the window is floating but not
|
||||
* maximized */
|
||||
|
@ -538,14 +558,17 @@ client_resize(Client *c, area_t geometry, Bool hints)
|
|||
titlebar_update_geometry_floating(c);
|
||||
}
|
||||
|
||||
XConfigureWindow(globalconf.display, c->win,
|
||||
CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc);
|
||||
xcb_configure_window(globalconf.connection, c->win,
|
||||
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
|
||||
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT |
|
||||
XCB_CONFIG_WINDOW_BORDER_WIDTH,
|
||||
values);
|
||||
window_configure(c->win, geometry, c->border);
|
||||
|
||||
if(c->screen != new_screen)
|
||||
move_client_to_screen(c, new_screen, False);
|
||||
move_client_to_screen(c, new_screen, false);
|
||||
|
||||
resized = True;
|
||||
resized = true;
|
||||
}
|
||||
|
||||
/* call it again like it was floating,
|
||||
|
@ -557,21 +580,19 @@ client_resize(Client *c, area_t geometry, Bool hints)
|
|||
}
|
||||
|
||||
void
|
||||
client_setfloating(Client *c, Bool floating, Layer layer)
|
||||
client_setfloating(Client *c, bool floating, Layer layer)
|
||||
{
|
||||
if(c->isfloating != floating)
|
||||
{
|
||||
if((c->isfloating = floating))
|
||||
{
|
||||
client_resize(c, c->f_geometry, False);
|
||||
}
|
||||
client_resize(c, c->f_geometry, false);
|
||||
else if(c->ismax)
|
||||
{
|
||||
c->ismax = False;
|
||||
client_resize(c, c->m_geometry, False);
|
||||
c->ismax = false;
|
||||
client_resize(c, c->m_geometry, false);
|
||||
}
|
||||
if(client_isvisible(c, c->screen))
|
||||
globalconf.screens[c->screen].need_arrange = True;
|
||||
globalconf.screens[c->screen].need_arrange = true;
|
||||
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
||||
if(floating)
|
||||
{
|
||||
|
@ -611,9 +632,9 @@ client_saveprops(Client *c)
|
|||
|
||||
prop[++i] = '\0';
|
||||
|
||||
XChangeProperty(globalconf.display, c->win,
|
||||
XInternAtom(globalconf.display, "_AWESOME_PROPERTIES", False),
|
||||
XA_STRING, 8, PropModeReplace, (unsigned char *) prop, i);
|
||||
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, c->win,
|
||||
x_intern_atom(globalconf.connection, "_AWESOME_PROPERTIES"),
|
||||
STRING, 8, i, (unsigned char *) prop);
|
||||
|
||||
p_delete(&prop);
|
||||
}
|
||||
|
@ -621,24 +642,23 @@ client_saveprops(Client *c)
|
|||
void
|
||||
client_unban(Client *c)
|
||||
{
|
||||
XMapWindow(globalconf.display, c->win);
|
||||
window_setstate(c->win, NormalState);
|
||||
xcb_map_window(globalconf.connection, c->win);
|
||||
window_setstate(c->win, XCB_WM_NORMAL_STATE);
|
||||
if(c->titlebar.sw && c->titlebar.position != Off)
|
||||
XMapWindow(globalconf.display, c->titlebar.sw->window);
|
||||
xcb_map_window(globalconf.connection, c->titlebar.sw->window);
|
||||
}
|
||||
|
||||
void
|
||||
client_unmanage(Client *c)
|
||||
{
|
||||
XWindowChanges wc;
|
||||
Tag *tag;
|
||||
|
||||
wc.border_width = c->oldborder;
|
||||
|
||||
/* The server grab construct avoids race conditions. */
|
||||
XGrabServer(globalconf.display);
|
||||
xcb_grab_server(globalconf.connection);
|
||||
|
||||
XConfigureWindow(globalconf.display, c->win, CWBorderWidth, &wc); /* restore border */
|
||||
xcb_configure_window(globalconf.connection, c->win,
|
||||
XCB_CONFIG_WINDOW_BORDER_WIDTH,
|
||||
(uint32_t *) &c->oldborder);
|
||||
|
||||
/* remove client everywhere */
|
||||
client_list_detach(&globalconf.clients, c);
|
||||
|
@ -649,13 +669,13 @@ client_unmanage(Client *c)
|
|||
untag_client(c, tag);
|
||||
|
||||
if(globalconf.focus->client == c)
|
||||
client_focus(NULL, c->screen, True);
|
||||
client_focus(NULL, c->screen, true);
|
||||
|
||||
XUngrabButton(globalconf.display, AnyButton, AnyModifier, c->win);
|
||||
window_setstate(c->win, WithdrawnState);
|
||||
xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY, c->win, ANY_MODIFIER);
|
||||
window_setstate(c->win, XCB_WM_WITHDRAWN_STATE);
|
||||
|
||||
XSync(globalconf.display, False);
|
||||
XUngrabServer(globalconf.display);
|
||||
xcb_aux_sync(globalconf.connection);
|
||||
xcb_ungrab_server(globalconf.connection);
|
||||
|
||||
if(c->titlebar.sw)
|
||||
simplewindow_delete(&c->titlebar.sw);
|
||||
|
@ -666,110 +686,91 @@ client_unmanage(Client *c)
|
|||
void
|
||||
client_updatewmhints(Client *c)
|
||||
{
|
||||
XWMHints *wmh;
|
||||
xcb_wm_hints_t *wmh;
|
||||
|
||||
if((wmh = XGetWMHints(globalconf.display, c->win)))
|
||||
if((wmh = xcb_get_wm_hints(globalconf.connection, c->win)))
|
||||
{
|
||||
if((c->isurgent = ((wmh->flags & XUrgencyHint) && globalconf.focus->client != c)))
|
||||
if((c->isurgent = (xcb_wm_hints_is_x_urgency_hint(wmh) && globalconf.focus->client != c)))
|
||||
{
|
||||
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
||||
titlebar_draw(c);
|
||||
}
|
||||
if((wmh->flags & StateHint) && wmh->initial_state == WithdrawnState)
|
||||
if(xcb_wm_hints_is_state_hint(wmh) && xcb_wm_hints_state_is_withdrawn(wmh))
|
||||
{
|
||||
c->border = 0;
|
||||
c->skip = True;
|
||||
c->skip = true;
|
||||
}
|
||||
XFree(wmh);
|
||||
free(wmh);
|
||||
}
|
||||
}
|
||||
|
||||
long
|
||||
xcb_size_hints_t *
|
||||
client_updatesizehints(Client *c)
|
||||
{
|
||||
long msize;
|
||||
XSizeHints size;
|
||||
xcb_size_hints_t *size = NULL;
|
||||
|
||||
if(!XGetWMNormalHints(globalconf.display, c->win, &size, &msize))
|
||||
return 0L;
|
||||
if(!xcb_get_wm_normal_hints(globalconf.connection, c->win, size, &msize) ||
|
||||
size == NULL)
|
||||
return NULL;
|
||||
|
||||
if(size.flags & PBaseSize)
|
||||
{
|
||||
c->basew = size.base_width;
|
||||
c->baseh = size.base_height;
|
||||
}
|
||||
else if(size.flags & PMinSize)
|
||||
{
|
||||
c->basew = size.min_width;
|
||||
c->baseh = size.min_height;
|
||||
}
|
||||
if(xcb_size_hints_is_p_size(size))
|
||||
xcb_size_hints_get_base_size(size, &c->basew, &c->baseh);
|
||||
else if(xcb_size_hints_is_p_min_size(size))
|
||||
xcb_size_hints_get_min_size(size, &c->basew, &c->baseh);
|
||||
else
|
||||
c->basew = c->baseh = 0;
|
||||
if(size.flags & PResizeInc)
|
||||
{
|
||||
c->incw = size.width_inc;
|
||||
c->inch = size.height_inc;
|
||||
}
|
||||
if(xcb_size_hints_is_p_resize_inc(size))
|
||||
xcb_size_hints_get_increase(size, &c->incw, &c->inch);
|
||||
else
|
||||
c->incw = c->inch = 0;
|
||||
|
||||
if(size.flags & PMaxSize)
|
||||
{
|
||||
c->maxw = size.max_width;
|
||||
c->maxh = size.max_height;
|
||||
}
|
||||
if(xcb_size_hints_is_p_max_size(size))
|
||||
xcb_size_hints_get_max_size(size, &c->maxw, &c->maxh);
|
||||
else
|
||||
c->maxw = c->maxh = 0;
|
||||
|
||||
if(size.flags & PMinSize)
|
||||
{
|
||||
c->minw = size.min_width;
|
||||
c->minh = size.min_height;
|
||||
}
|
||||
else if(size.flags & PBaseSize)
|
||||
{
|
||||
c->minw = size.base_width;
|
||||
c->minh = size.base_height;
|
||||
}
|
||||
if(xcb_size_hints_is_p_min_size(size))
|
||||
xcb_size_hints_get_min_size(size, &c->minw, &c->minh);
|
||||
else if(xcb_size_hints_is_p_base_size(size))
|
||||
xcb_size_hints_get_base_size(size, &c->minw, &c->minh);
|
||||
else
|
||||
c->minw = c->minh = 0;
|
||||
|
||||
if(size.flags & PAspect)
|
||||
if(xcb_size_hints_is_p_aspect(size))
|
||||
{
|
||||
c->minax = size.min_aspect.x;
|
||||
c->maxax = size.max_aspect.x;
|
||||
c->minay = size.min_aspect.y;
|
||||
c->maxay = size.max_aspect.y;
|
||||
xcb_size_hints_get_min_aspect(size, &c->minax, &c->minay);
|
||||
xcb_size_hints_get_max_aspect(size, &c->maxax, &c->maxay);
|
||||
}
|
||||
else
|
||||
c->minax = c->maxax = c->minay = c->maxay = 0;
|
||||
|
||||
if(c->maxw && c->minw && c->maxh && c->minh
|
||||
&& c->maxw == c->minw && c->maxh == c->minh)
|
||||
c->isfixed = True;
|
||||
c->isfixed = true;
|
||||
|
||||
return size.flags;
|
||||
return size;
|
||||
}
|
||||
|
||||
/** Returns True if a client is tagged
|
||||
/** Returns true if a client is tagged
|
||||
* with one of the tags
|
||||
* \return True or False
|
||||
* \return true or false
|
||||
*/
|
||||
Bool
|
||||
bool
|
||||
client_isvisible(Client *c, int screen)
|
||||
{
|
||||
Tag *tag;
|
||||
|
||||
if(!c || c->screen != screen)
|
||||
return False;
|
||||
return false;
|
||||
|
||||
if(globalconf.scratch.client == c)
|
||||
return globalconf.scratch.isvisible;
|
||||
|
||||
for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
|
||||
if(tag->selected && is_client_tagged(c, tag))
|
||||
return True;
|
||||
return False;
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Set the transparency of the selected client.
|
||||
|
@ -781,27 +782,28 @@ client_isvisible(Client *c, int screen)
|
|||
void
|
||||
uicb_client_settrans(int screen __attribute__ ((unused)), char *arg)
|
||||
{
|
||||
double delta = 1.0, current_opacity = 1.0;
|
||||
unsigned char *data;
|
||||
Atom actual;
|
||||
int format;
|
||||
unsigned long n, left;
|
||||
double delta = 1.0, current_opacity = 100.0;
|
||||
unsigned int current_opacity_raw = 0;
|
||||
int set_prop = 0;
|
||||
Client *sel = globalconf.focus->client;
|
||||
xcb_get_property_reply_t *prop_r;
|
||||
|
||||
if(!sel)
|
||||
return;
|
||||
|
||||
XGetWindowProperty(globalconf.display, sel->win,
|
||||
XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False),
|
||||
0L, 1L, False, XA_CARDINAL, &actual, &format, &n, &left,
|
||||
(unsigned char **) &data);
|
||||
if(data)
|
||||
prop_r = xcb_get_property_reply(globalconf.connection,
|
||||
xcb_get_property_unchecked(globalconf.connection,
|
||||
false, sel->win,
|
||||
x_intern_atom(globalconf.connection, "_NET_WM_WINDOW_OPACITY"),
|
||||
CARDINAL,
|
||||
0, 1),
|
||||
NULL);
|
||||
|
||||
if(prop_r)
|
||||
{
|
||||
memcpy(¤t_opacity_raw, data, sizeof(unsigned int));
|
||||
XFree(data);
|
||||
memcpy(¤t_opacity_raw, xcb_get_property_value(prop_r), sizeof(unsigned int));
|
||||
current_opacity = (double) current_opacity_raw / 0xffffffff;
|
||||
p_delete(&prop_r);
|
||||
}
|
||||
else
|
||||
set_prop = 1;
|
||||
|
@ -829,7 +831,7 @@ uicb_client_settrans(int screen __attribute__ ((unused)), char *arg)
|
|||
* \return next or previous client
|
||||
*/
|
||||
static Client *
|
||||
client_find_visible(Client *sel, Bool reverse)
|
||||
client_find_visible(Client *sel, bool reverse)
|
||||
{
|
||||
Client *next;
|
||||
Client *(*client_iter)(Client **, Client *) = client_list_next_cycle;
|
||||
|
@ -858,10 +860,10 @@ uicb_client_swapprev(int screen __attribute__ ((unused)), char *arg __attribute_
|
|||
{
|
||||
Client *prev;
|
||||
|
||||
if((prev = client_find_visible(globalconf.focus->client, True)))
|
||||
if((prev = client_find_visible(globalconf.focus->client, true)))
|
||||
{
|
||||
client_list_swap(&globalconf.clients, prev, globalconf.focus->client);
|
||||
globalconf.screens[prev->screen].need_arrange = True;
|
||||
globalconf.screens[prev->screen].need_arrange = true;
|
||||
widget_invalidate_cache(prev->screen, WIDGET_CACHE_CLIENTS);
|
||||
}
|
||||
}
|
||||
|
@ -876,10 +878,10 @@ uicb_client_swapnext(int screen __attribute__ ((unused)), char *arg __attribute_
|
|||
{
|
||||
Client *next;
|
||||
|
||||
if((next = client_find_visible(globalconf.focus->client, False)))
|
||||
if((next = client_find_visible(globalconf.focus->client, false)))
|
||||
{
|
||||
client_list_swap(&globalconf.clients, globalconf.focus->client, next);
|
||||
globalconf.screens[next->screen].need_arrange = True;
|
||||
globalconf.screens[next->screen].need_arrange = true;
|
||||
widget_invalidate_cache(next->screen, WIDGET_CACHE_CLIENTS);
|
||||
}
|
||||
}
|
||||
|
@ -895,11 +897,10 @@ uicb_client_moveresize(int screen, char *arg)
|
|||
{
|
||||
int ox, oy, ow, oh; /* old geometry */
|
||||
char x[8], y[8], w[8], h[8];
|
||||
int mx, my, dx, dy, nmx, nmy;
|
||||
unsigned int dui;
|
||||
Window dummy;
|
||||
int nmx, nmy;
|
||||
area_t geometry;
|
||||
Client *sel = globalconf.focus->client;
|
||||
xcb_query_pointer_reply_t *xqp;
|
||||
Layout *curlay = layout_get_current(screen);
|
||||
|
||||
if(!sel || sel->isfixed || !arg ||
|
||||
|
@ -919,26 +920,26 @@ uicb_client_moveresize(int screen, char *arg)
|
|||
ow = sel->geometry.width;
|
||||
oh = sel->geometry.height;
|
||||
|
||||
Bool xqp = XQueryPointer(globalconf.display,
|
||||
RootWindow(globalconf.display,
|
||||
sel->phys_screen),
|
||||
&dummy, &dummy, &mx, &my, &dx, &dy, &dui);
|
||||
xqp = xcb_query_pointer_reply(globalconf.connection,
|
||||
xcb_query_pointer_unchecked(globalconf.connection,
|
||||
root_window(globalconf.connection, sel->phys_screen)),
|
||||
NULL);
|
||||
if(globalconf.screens[sel->screen].resize_hints)
|
||||
geometry = client_geometry_hints(sel, geometry);
|
||||
client_resize(sel, geometry, False);
|
||||
if (xqp && ox <= mx && (ox + 2 * sel->border + ow) >= mx &&
|
||||
oy <= my && (oy + 2 * sel->border + oh) >= my)
|
||||
client_resize(sel, geometry, false);
|
||||
if (xqp && ox <= xqp->root_x && (ox + 2 * sel->border + ow) >= xqp->root_x &&
|
||||
oy <= xqp->root_y && (oy + 2 * sel->border + oh) >= xqp->root_y)
|
||||
{
|
||||
nmx = mx - (ox + sel->border) + sel->geometry.width - ow;
|
||||
nmy = my - (oy + sel->border) + sel->geometry.height - oh;
|
||||
nmx = xqp->root_x - (ox + sel->border) + sel->geometry.width - ow;
|
||||
nmy = xqp->root_y - (oy + sel->border) + sel->geometry.height - oh;
|
||||
|
||||
if(nmx < -sel->border) /* can happen on a resize */
|
||||
nmx = -sel->border;
|
||||
if(nmy < -sel->border)
|
||||
nmy = -sel->border;
|
||||
|
||||
XWarpPointer(globalconf.display,
|
||||
None, sel->win,
|
||||
xcb_warp_pointer(globalconf.connection,
|
||||
XCB_NONE, sel->win,
|
||||
0, 0, 0, 0, nmx, nmy);
|
||||
}
|
||||
}
|
||||
|
@ -950,20 +951,24 @@ uicb_client_moveresize(int screen, char *arg)
|
|||
void
|
||||
client_kill(Client *c)
|
||||
{
|
||||
XEvent ev;
|
||||
xcb_client_message_event_t ev;
|
||||
|
||||
if(client_isprotodel(globalconf.display, c->win))
|
||||
if(client_isprotodel(globalconf.connection, c->win))
|
||||
{
|
||||
ev.type = ClientMessage;
|
||||
ev.xclient.window = c->win;
|
||||
ev.xclient.message_type = XInternAtom(globalconf.display, "WM_PROTOCOLS", False);
|
||||
ev.xclient.format = 32;
|
||||
ev.xclient.data.l[0] = XInternAtom(globalconf.display, "WM_DELETE_WINDOW", False);
|
||||
ev.xclient.data.l[1] = CurrentTime;
|
||||
XSendEvent(globalconf.display, c->win, False, NoEventMask, &ev);
|
||||
ev.window = c->win;
|
||||
ev.type = x_intern_atom(globalconf.connection, "WM_PROTOCOLS");
|
||||
|
||||
ev.data.data32[0] = x_intern_atom(globalconf.connection, "WM_DELETE_WINDOW");
|
||||
ev.data.data32[1] = XCB_CURRENT_TIME;
|
||||
|
||||
/* TODO: really useful? */
|
||||
ev.data.data32[2] = ev.data.data32[3] = ev.data.data32[4] = 0;
|
||||
|
||||
xcb_send_event(globalconf.connection, false, c->win,
|
||||
XCB_EVENT_MASK_NO_EVENT, (char *) &ev);
|
||||
}
|
||||
else
|
||||
XKillClient(globalconf.display, c->win);
|
||||
xcb_kill_client(globalconf.connection, c->win);
|
||||
}
|
||||
|
||||
/** Kill the currently focused client.
|
||||
|
@ -994,25 +999,26 @@ client_maximize(Client *c, area_t geometry)
|
|||
c->wasfloating = c->isfloating;
|
||||
c->m_geometry = c->geometry;
|
||||
if(layout_get_current(c->screen)->arrange != layout_floating)
|
||||
client_setfloating(c, True, LAYER_FULLSCREEN);
|
||||
client_focus(c, c->screen, True);
|
||||
client_resize(c, geometry, False);
|
||||
client_setfloating(c, true, LAYER_FULLSCREEN);
|
||||
client_focus(c, c->screen, true);
|
||||
client_resize(c, geometry, false);
|
||||
}
|
||||
else if(c->wasfloating)
|
||||
{
|
||||
c->titlebar.position = c->titlebar.dposition;
|
||||
client_setfloating(c, True, LAYER_FULLSCREEN);
|
||||
client_resize(c, c->m_geometry, False);
|
||||
client_setfloating(c, true, LAYER_FULLSCREEN);
|
||||
client_resize(c, c->m_geometry, false);
|
||||
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
||||
}
|
||||
else if(layout_get_current(c->screen)->arrange == layout_floating)
|
||||
{
|
||||
c->titlebar.position = c->titlebar.dposition;
|
||||
client_resize(c, c->m_geometry, False);
|
||||
client_resize(c, c->m_geometry, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
c->titlebar.position = c->titlebar.dposition;
|
||||
client_setfloating(c, False, LAYER_TILE);
|
||||
client_setfloating(c, false, LAYER_TILE);
|
||||
}
|
||||
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
||||
}
|
||||
|
@ -1104,7 +1110,7 @@ uicb_client_zoom(int screen, char *arg __attribute__ ((unused)))
|
|||
{
|
||||
client_list_detach(&globalconf.clients, sel);
|
||||
client_list_push(&globalconf.clients, sel);
|
||||
globalconf.screens[screen].need_arrange = True;
|
||||
globalconf.screens[screen].need_arrange = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1118,8 +1124,8 @@ uicb_client_focusnext(int screen, char *arg __attribute__ ((unused)))
|
|||
{
|
||||
Client *next;
|
||||
|
||||
if((next = client_find_visible(globalconf.focus->client, False)))
|
||||
client_focus(next, screen, True);
|
||||
if((next = client_find_visible(globalconf.focus->client, false)))
|
||||
client_focus(next, screen, true);
|
||||
}
|
||||
|
||||
/** Give focus to the previous visible client in the stack.
|
||||
|
@ -1132,8 +1138,8 @@ uicb_client_focusprev(int screen, char *arg __attribute__ ((unused)))
|
|||
{
|
||||
Client *prev;
|
||||
|
||||
if((prev = client_find_visible(globalconf.focus->client, True)))
|
||||
client_focus(prev, screen, True);
|
||||
if((prev = client_find_visible(globalconf.focus->client, true)))
|
||||
client_focus(prev, screen, true);
|
||||
}
|
||||
|
||||
/** Toggle the floating state of the focused client.
|
||||
|
@ -1166,7 +1172,7 @@ uicb_client_setscratch(int screen, char *arg __attribute__ ((unused)))
|
|||
globalconf.scratch.client = globalconf.focus->client;
|
||||
|
||||
widget_invalidate_cache(screen, WIDGET_CACHE_CLIENTS | WIDGET_CACHE_TAGS);
|
||||
globalconf.screens[screen].need_arrange = True;
|
||||
globalconf.screens[screen].need_arrange = true;
|
||||
}
|
||||
|
||||
/** Toggle the scratch client's visibility.
|
||||
|
@ -1181,8 +1187,8 @@ uicb_client_togglescratch(int screen, char *arg __attribute__ ((unused)))
|
|||
{
|
||||
globalconf.scratch.isvisible = !globalconf.scratch.isvisible;
|
||||
if(globalconf.scratch.isvisible)
|
||||
client_focus(globalconf.scratch.client, screen, True);
|
||||
globalconf.screens[globalconf.scratch.client->screen].need_arrange = True;
|
||||
client_focus(globalconf.scratch.client, screen, true);
|
||||
globalconf.screens[globalconf.scratch.client->screen].need_arrange = true;
|
||||
widget_invalidate_cache(globalconf.scratch.client->screen, WIDGET_CACHE_CLIENTS);
|
||||
}
|
||||
}
|
||||
|
|
18
client.h
18
client.h
|
@ -22,24 +22,28 @@
|
|||
#ifndef AWESOME_CLIENT_H
|
||||
#define AWESOME_CLIENT_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <xcb/xcb_icccm.h>
|
||||
|
||||
#include "structs.h"
|
||||
|
||||
Bool client_isvisible(Client *, int);
|
||||
Client * client_get_bywin(Client *, Window);
|
||||
bool client_isvisible(Client *, int);
|
||||
Client * client_get_bywin(Client *, xcb_window_t);
|
||||
Client * client_get_byname(Client *, char *);
|
||||
Bool client_focus(Client *, int, Bool);
|
||||
bool client_focus(Client *, int, bool);
|
||||
void client_stack(Client *);
|
||||
void client_ban(Client *);
|
||||
void client_unban(Client *);
|
||||
void client_manage(Window, XWindowAttributes *, int);
|
||||
Bool client_resize(Client *, area_t, Bool);
|
||||
void client_manage(xcb_window_t, xcb_get_geometry_reply_t *, int);
|
||||
bool client_resize(Client *, area_t, bool);
|
||||
void client_unmanage(Client *);
|
||||
void client_updatewmhints(Client *);
|
||||
long client_updatesizehints(Client *);
|
||||
xcb_size_hints_t *client_updatesizehints(Client *);
|
||||
void client_updatetitle(Client *);
|
||||
void client_saveprops(Client *);
|
||||
void client_kill(Client *);
|
||||
void client_setfloating(Client *, Bool, Layer);
|
||||
void client_setfloating(Client *, bool, Layer);
|
||||
|
||||
Uicb uicb_client_kill;
|
||||
Uicb uicb_client_moveresize;
|
||||
|
|
|
@ -235,7 +235,7 @@ cfg_opt_t mouse_taglist_opts[] =
|
|||
/** Modifier keys. */
|
||||
CFG_STR_LIST((char *) "modkey", (char *) "{}", CFGF_NONE),
|
||||
/** Mouse button. */
|
||||
CFG_STR((char *) "button", (char *) "None", CFGF_NONE),
|
||||
CFG_STR((char *) "button", (char *) "XCB_NONE", CFGF_NONE),
|
||||
/** Uicb command to run. */
|
||||
CFG_STR((char *) "command", NULL, CFGF_NONE),
|
||||
CFG_AWESOME_END()
|
||||
|
@ -246,7 +246,7 @@ cfg_opt_t mouse_generic_opts[] =
|
|||
/** Modifier keys. */
|
||||
CFG_STR_LIST((char *) "modkey", (char *) "{}", CFGF_NONE),
|
||||
/** Mouse button. */
|
||||
CFG_STR((char *) "button", (char *) "None", CFGF_NONE),
|
||||
CFG_STR((char *) "button", (char *) "XCB_NONE", CFGF_NONE),
|
||||
/** Uicb command to run. */
|
||||
CFG_STR((char *) "command", NULL, CFGF_NONE),
|
||||
/** Argument to use for command. */
|
||||
|
@ -580,7 +580,7 @@ cfg_opt_t key_opts[] =
|
|||
/** Modifier keys. */
|
||||
CFG_STR_LIST((char *) "modkey", (char *) "", CFGF_NONE),
|
||||
/** Key to press. */
|
||||
CFG_STR((char *) "key", (char *) "None", CFGF_NONE),
|
||||
CFG_STR((char *) "key", (char *) "XCB_NONE", CFGF_NONE),
|
||||
/** Uicb command to run. */
|
||||
CFG_STR((char *) "command", (char *) "", CFGF_NONE),
|
||||
/** Argument to use for command. */
|
||||
|
|
145
common/draw.c
145
common/draw.c
|
@ -19,7 +19,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <cairo-xlib.h>
|
||||
#include <cairo-xcb.h>
|
||||
|
||||
#ifdef HAVE_GTK
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
|
@ -27,14 +28,19 @@
|
|||
#include <Imlib2.h>
|
||||
#endif
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_aux.h>
|
||||
|
||||
#include <langinfo.h>
|
||||
#include <iconv.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "draw.h"
|
||||
#include "common/util.h"
|
||||
#include "common/xutil.h"
|
||||
|
||||
/** Convert text from any charset to UTF-8 using iconv
|
||||
* \param iso the ISO string to convert
|
||||
|
@ -80,8 +86,27 @@ draw_iso2utf8(char *iso)
|
|||
return utf8p;
|
||||
}
|
||||
|
||||
static xcb_visualtype_t *
|
||||
default_visual_from_screen(xcb_screen_t *s)
|
||||
{
|
||||
xcb_depth_iterator_t depth_iter;
|
||||
xcb_visualtype_iterator_t visual_iter;
|
||||
|
||||
if(!s)
|
||||
return NULL;
|
||||
|
||||
for(depth_iter = xcb_screen_allowed_depths_iterator(s);
|
||||
depth_iter.rem; xcb_depth_next (&depth_iter))
|
||||
for(visual_iter = xcb_depth_visuals_iterator (depth_iter.data);
|
||||
visual_iter.rem; xcb_visualtype_next (&visual_iter))
|
||||
if (s->root_visual == visual_iter.data->visual_id)
|
||||
return visual_iter.data;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** Get a draw context
|
||||
* \param disp Display ref
|
||||
* \param conn Connection ref
|
||||
* \param phys_screen physical screen id
|
||||
* \param width width
|
||||
* \param height height
|
||||
|
@ -89,18 +114,19 @@ draw_iso2utf8(char *iso)
|
|||
* \return draw context ref
|
||||
*/
|
||||
DrawCtx *
|
||||
draw_context_new(Display *disp, int phys_screen, int width, int height, Drawable dw)
|
||||
draw_context_new(xcb_connection_t *conn, int phys_screen, int width, int height, xcb_drawable_t dw)
|
||||
{
|
||||
DrawCtx *d = p_new(DrawCtx, 1);
|
||||
xcb_screen_t *s = xcb_aux_get_screen(conn, phys_screen);
|
||||
|
||||
d->display = disp;
|
||||
d->connection = conn;
|
||||
d->phys_screen = phys_screen;
|
||||
d->width = width;
|
||||
d->height = height;
|
||||
d->depth = DefaultDepth(disp, phys_screen);
|
||||
d->visual = DefaultVisual(disp, phys_screen);
|
||||
d->depth = s->root_depth;
|
||||
d->visual = default_visual_from_screen(s);
|
||||
d->drawable = dw;
|
||||
d->surface = cairo_xlib_surface_create(disp, dw, d->visual, width, height);
|
||||
d->surface = cairo_xcb_surface_create(conn, dw, d->visual, width, height);
|
||||
d->cr = cairo_create(d->surface);
|
||||
d->layout = pango_cairo_create_layout(d->cr);
|
||||
|
||||
|
@ -120,25 +146,26 @@ draw_context_delete(DrawCtx **ctx)
|
|||
}
|
||||
|
||||
/** Create a new Pango font
|
||||
* \param disp Display ref
|
||||
* \param conn Connection ref
|
||||
* \param fontname Pango fontname (e.g. [FAMILY-LIST] [STYLE-OPTIONS] [SIZE])
|
||||
* \return a new font
|
||||
*/
|
||||
font_t *
|
||||
draw_font_new(Display *disp, char *fontname)
|
||||
draw_font_new(xcb_connection_t *conn, int phys_screen, char *fontname)
|
||||
{
|
||||
cairo_surface_t *surface;
|
||||
xcb_screen_t *s = xcb_aux_get_screen(conn, phys_screen);
|
||||
cairo_t *cr;
|
||||
PangoLayout *layout;
|
||||
font_t *font = p_new(font_t, 1);
|
||||
|
||||
/* Create a dummy cairo surface, cairo context and pango layout in
|
||||
* order to get font informations */
|
||||
surface = cairo_xlib_surface_create(disp,
|
||||
DefaultScreen(disp),
|
||||
DefaultVisual(disp, DefaultScreen(disp)),
|
||||
DisplayWidth(disp, DefaultScreen(disp)),
|
||||
DisplayHeight(disp, DefaultScreen(disp)));
|
||||
surface = cairo_xcb_surface_create(conn,
|
||||
phys_screen,
|
||||
default_visual_from_screen(s),
|
||||
s->width_in_pixels,
|
||||
s->height_in_pixels);
|
||||
|
||||
cr = cairo_create(surface);
|
||||
layout = pango_cairo_create_layout(cr);
|
||||
|
@ -207,7 +234,7 @@ draw_text(DrawCtx *ctx,
|
|||
ssize_t len, olen;
|
||||
char *buf = NULL, *utf8 = NULL;
|
||||
|
||||
draw_rectangle(ctx, area, 1.0, True, style.bg);
|
||||
draw_rectangle(ctx, area, 1.0, true, style.bg);
|
||||
|
||||
if(!(len = olen = a_strlen(text)))
|
||||
return;
|
||||
|
@ -222,7 +249,7 @@ draw_text(DrawCtx *ctx,
|
|||
buf = a_strdup(text);
|
||||
|
||||
/* check that the text is not too long */
|
||||
while(len && (nw = (draw_textwidth(ctx->display, style.font, buf)) + padding * 2) > area.width)
|
||||
while(len && (nw = (draw_textwidth(ctx->connection, ctx->default_screen, style.font, buf)) + padding * 2) > area.width)
|
||||
{
|
||||
len--;
|
||||
/* we can't blindly null the char, we need to check if it's not part of
|
||||
|
@ -297,8 +324,8 @@ draw_text(DrawCtx *ctx,
|
|||
*/
|
||||
static cairo_pattern_t *
|
||||
draw_setup_cairo_color_source(DrawCtx *ctx, area_t rect,
|
||||
XColor *pcolor, XColor *pcolor_center,
|
||||
XColor *pcolor_end)
|
||||
xcolor_t *pcolor, xcolor_t *pcolor_center,
|
||||
xcolor_t *pcolor_end)
|
||||
{
|
||||
cairo_pattern_t *pat = NULL;
|
||||
|
||||
|
@ -336,7 +363,7 @@ draw_setup_cairo_color_source(DrawCtx *ctx, area_t rect,
|
|||
* \param color color to use
|
||||
*/
|
||||
void
|
||||
draw_rectangle(DrawCtx *ctx, area_t geometry, float line_width, Bool filled, XColor color)
|
||||
draw_rectangle(DrawCtx *ctx, area_t geometry, float line_width, bool filled, xcolor_t color)
|
||||
{
|
||||
cairo_set_antialias(ctx->cr, CAIRO_ANTIALIAS_NONE);
|
||||
cairo_set_line_width(ctx->cr, line_width);
|
||||
|
@ -372,9 +399,9 @@ draw_rectangle(DrawCtx *ctx, area_t geometry, float line_width, Bool filled, XCo
|
|||
* \param pcolor_end color at pattern_start + pattern_width
|
||||
*/
|
||||
void
|
||||
draw_rectangle_gradient(DrawCtx *ctx, area_t geometry, float line_width, Bool filled,
|
||||
area_t pattern_rect, XColor *pcolor,
|
||||
XColor *pcolor_center, XColor *pcolor_end)
|
||||
draw_rectangle_gradient(DrawCtx *ctx, area_t geometry, float line_width, bool filled,
|
||||
area_t pattern_rect, xcolor_t *pcolor,
|
||||
xcolor_t *pcolor_center, xcolor_t *pcolor_end)
|
||||
{
|
||||
cairo_pattern_t *pat;
|
||||
|
||||
|
@ -430,7 +457,7 @@ draw_graph_setup(DrawCtx *ctx)
|
|||
void
|
||||
draw_graph(DrawCtx *ctx, area_t rect, int *from, int *to, int cur_index,
|
||||
Position grow, area_t patt_rect,
|
||||
XColor *pcolor, XColor *pcolor_center, XColor *pcolor_end)
|
||||
xcolor_t *pcolor, xcolor_t *pcolor_center, xcolor_t *pcolor_end)
|
||||
{
|
||||
int i, y, w;
|
||||
float x;
|
||||
|
@ -492,7 +519,7 @@ draw_graph(DrawCtx *ctx, area_t rect, int *from, int *to, int cur_index,
|
|||
void
|
||||
draw_graph_line(DrawCtx *ctx, area_t rect, int *to, int cur_index,
|
||||
Position grow, area_t patt_rect,
|
||||
XColor *pcolor, XColor *pcolor_center, XColor *pcolor_end)
|
||||
xcolor_t *pcolor, xcolor_t *pcolor_center, xcolor_t *pcolor_end)
|
||||
{
|
||||
int i, w;
|
||||
float x, y;
|
||||
|
@ -564,7 +591,7 @@ draw_graph_line(DrawCtx *ctx, area_t rect, int *to, int cur_index,
|
|||
* \param color color to use
|
||||
*/
|
||||
void
|
||||
draw_circle(DrawCtx *ctx, int x, int y, int r, Bool filled, XColor color)
|
||||
draw_circle(DrawCtx *ctx, int x, int y, int r, bool filled, xcolor_t color)
|
||||
{
|
||||
cairo_set_line_width(ctx->cr, 1.0);
|
||||
cairo_set_source_rgb(ctx->cr, color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0);
|
||||
|
@ -811,15 +838,15 @@ draw_get_image_size(const char *filename)
|
|||
* \return new rotated drawable
|
||||
*/
|
||||
void
|
||||
draw_rotate(DrawCtx *ctx, Drawable dest, int dest_w, int dest_h,
|
||||
draw_rotate(DrawCtx *ctx, xcb_drawable_t dest, int dest_w, int dest_h,
|
||||
double angle, int tx, int ty)
|
||||
{
|
||||
cairo_surface_t *surface, *source;
|
||||
cairo_t *cr;
|
||||
|
||||
surface = cairo_xlib_surface_create(ctx->display, dest,
|
||||
surface = cairo_xcb_surface_create(ctx->connection, dest,
|
||||
ctx->visual, dest_w, dest_h);
|
||||
source = cairo_xlib_surface_create(ctx->display, ctx->drawable,
|
||||
source = cairo_xcb_surface_create(ctx->connection, ctx->drawable,
|
||||
ctx->visual, ctx->width, ctx->height);
|
||||
cr = cairo_create (surface);
|
||||
|
||||
|
@ -835,26 +862,27 @@ draw_rotate(DrawCtx *ctx, Drawable dest, int dest_w, int dest_h,
|
|||
}
|
||||
|
||||
/** Return the width of a text in pixel
|
||||
* \param disp Display ref
|
||||
* \param conn Connection ref
|
||||
* \param font font to use
|
||||
* \param text the text
|
||||
* \return text width
|
||||
*/
|
||||
unsigned short
|
||||
draw_textwidth(Display *disp, font_t *font, const char *text)
|
||||
draw_textwidth(xcb_connection_t *conn, int default_screen, font_t *font, const char *text)
|
||||
{
|
||||
cairo_surface_t *surface;
|
||||
cairo_t *cr;
|
||||
PangoLayout *layout;
|
||||
PangoRectangle ext;
|
||||
xcb_screen_t *s = xcb_aux_get_screen(conn, default_screen);
|
||||
|
||||
if(!a_strlen(text))
|
||||
return 0;
|
||||
|
||||
surface = cairo_xlib_surface_create(disp, DefaultScreen(disp),
|
||||
DefaultVisual(disp, DefaultScreen(disp)),
|
||||
DisplayWidth(disp, DefaultScreen(disp)),
|
||||
DisplayHeight(disp, DefaultScreen(disp)));
|
||||
surface = cairo_xcb_surface_create(conn, default_screen,
|
||||
default_visual_from_screen(s),
|
||||
s->width_in_pixels,
|
||||
s->height_in_pixels);
|
||||
cr = cairo_create(surface);
|
||||
layout = pango_cairo_create_layout(cr);
|
||||
pango_layout_set_text(layout, text, -1);
|
||||
|
@ -889,29 +917,40 @@ draw_align_get_from_str(const char *align)
|
|||
}
|
||||
|
||||
/** Initialize an X color
|
||||
* \param disp display ref
|
||||
* \param conn Connection ref
|
||||
* \param phys_screen Physical screen number
|
||||
* \param colstr Color specification
|
||||
* \param color XColor struct to store color to
|
||||
* \param color xcolor_t struct to store color to
|
||||
* \return true if color allocation was successfull
|
||||
*/
|
||||
Bool
|
||||
draw_color_new(Display *disp, int phys_screen, const char *colstr, XColor *color)
|
||||
bool
|
||||
draw_color_new(xcb_connection_t *conn, int phys_screen, const char *colstr, xcolor_t *color)
|
||||
{
|
||||
Bool ret;
|
||||
XColor exactColor;
|
||||
xcb_alloc_named_color_reply_t *c;
|
||||
xcb_screen_t *s = xcb_aux_get_screen(conn, phys_screen);
|
||||
|
||||
if(!a_strlen(colstr))
|
||||
return False;
|
||||
return false;
|
||||
|
||||
if(!(ret = XAllocNamedColor(disp,
|
||||
DefaultColormap(disp, phys_screen),
|
||||
colstr,
|
||||
color,
|
||||
&exactColor)))
|
||||
if((c = xcb_alloc_named_color_reply(conn,
|
||||
xcb_alloc_named_color(conn,
|
||||
s->default_colormap,
|
||||
strlen(colstr),
|
||||
colstr),
|
||||
NULL)) == NULL)
|
||||
{
|
||||
warn("awesome: error, cannot allocate color '%s'\n", colstr);
|
||||
return false;
|
||||
}
|
||||
|
||||
return ret;
|
||||
color->pixel = c->pixel;
|
||||
color->red = c->visual_red;
|
||||
color->green = c->visual_green;
|
||||
color->blue = c->visual_blue;
|
||||
|
||||
p_delete(&c);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Init a style struct. Every value will be inherited from m
|
||||
|
@ -923,7 +962,7 @@ draw_color_new(Display *disp, int phys_screen, const char *colstr, XColor *color
|
|||
* \param m style to use as template
|
||||
*/
|
||||
void
|
||||
draw_style_init(Display *disp, int phys_screen, cfg_t *cfg,
|
||||
draw_style_init(xcb_connection_t *conn, int phys_screen, cfg_t *cfg,
|
||||
style_t *c, style_t *m)
|
||||
{
|
||||
char *buf;
|
||||
|
@ -936,18 +975,18 @@ draw_style_init(Display *disp, int phys_screen, cfg_t *cfg,
|
|||
return;
|
||||
|
||||
if((buf = cfg_getstr(cfg, "font")))
|
||||
c->font = draw_font_new(disp, buf);
|
||||
c->font = draw_font_new(conn, phys_screen, buf);
|
||||
|
||||
draw_color_new(disp, phys_screen,
|
||||
draw_color_new(conn, phys_screen,
|
||||
cfg_getstr(cfg, "fg"), &c->fg);
|
||||
|
||||
draw_color_new(disp, phys_screen,
|
||||
draw_color_new(conn, phys_screen,
|
||||
cfg_getstr(cfg, "bg"), &c->bg);
|
||||
|
||||
draw_color_new(disp, phys_screen,
|
||||
draw_color_new(conn, phys_screen,
|
||||
cfg_getstr(cfg, "border"), &c->border);
|
||||
|
||||
draw_color_new(disp, phys_screen,
|
||||
draw_color_new(conn, phys_screen,
|
||||
cfg_getstr(cfg, "shadow"), &c->shadow);
|
||||
|
||||
if((shadow = cfg_getint(cfg, "shadow_offset")) != (int) 0xffffffff)
|
||||
|
|
|
@ -23,14 +23,15 @@
|
|||
#define AWESOME_COMMON_DRAW_H
|
||||
|
||||
#include <cairo.h>
|
||||
#include <pango/pangocairo.h>
|
||||
|
||||
#include <confuse.h>
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <pango/pangocairo.h>
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
#include "common/util.h"
|
||||
#include "common/list.h"
|
||||
#include "common/xutil.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
@ -59,7 +60,7 @@ DO_SLIST(area_t, area, p_delete)
|
|||
#define AREA_RIGHT(a) ((a).x + (a).width)
|
||||
#define AREA_BOTTOM(a) ((a).y + (a).height)
|
||||
|
||||
static inline Bool
|
||||
static inline bool
|
||||
area_intersect_area(area_t a, area_t b)
|
||||
{
|
||||
return (b.x < a.x + a.width
|
||||
|
@ -90,13 +91,13 @@ typedef struct
|
|||
typedef struct
|
||||
{
|
||||
/** Foreground color */
|
||||
XColor fg;
|
||||
xcolor_t fg;
|
||||
/** Background color */
|
||||
XColor bg;
|
||||
xcolor_t bg;
|
||||
/** Shadow color */
|
||||
XColor shadow;
|
||||
xcolor_t shadow;
|
||||
/** Border color */
|
||||
XColor border;
|
||||
xcolor_t border;
|
||||
/** Shadow offset */
|
||||
int shadow_offset;
|
||||
/** Font */
|
||||
|
@ -105,9 +106,10 @@ typedef struct
|
|||
|
||||
typedef struct
|
||||
{
|
||||
Display *display;
|
||||
Drawable drawable;
|
||||
Visual *visual;
|
||||
xcb_connection_t *connection;
|
||||
int default_screen;
|
||||
xcb_drawable_t drawable;
|
||||
xcb_visualtype_t *visual;
|
||||
int width;
|
||||
int height;
|
||||
int phys_screen;
|
||||
|
@ -117,28 +119,28 @@ typedef struct
|
|||
PangoLayout *layout;
|
||||
} DrawCtx;
|
||||
|
||||
DrawCtx *draw_context_new(Display *, int, int, int, Drawable);
|
||||
DrawCtx *draw_context_new(xcb_connection_t *, int, int, int, xcb_drawable_t);
|
||||
void draw_context_delete(DrawCtx **);
|
||||
|
||||
font_t *draw_font_new(Display *disp, char *fontname);
|
||||
font_t *draw_font_new(xcb_connection_t *, int, char *);
|
||||
void draw_font_delete(font_t **);
|
||||
|
||||
void draw_text(DrawCtx *, area_t, Alignment, int, char *, style_t);
|
||||
void draw_rectangle(DrawCtx *, area_t, float, Bool, XColor);
|
||||
void draw_rectangle_gradient(DrawCtx *, area_t, float, Bool, area_t, XColor *, XColor *, XColor *);
|
||||
void draw_rectangle(DrawCtx *, area_t, float, bool, xcolor_t);
|
||||
void draw_rectangle_gradient(DrawCtx *, area_t, float, bool, area_t, xcolor_t *, xcolor_t *, xcolor_t *);
|
||||
|
||||
void draw_graph_setup(DrawCtx *);
|
||||
void draw_graph(DrawCtx *, area_t, int *, int *, int, Position, area_t, XColor *, XColor *, XColor *);
|
||||
void draw_graph_line(DrawCtx *, area_t, int *, int, Position, area_t, XColor *, XColor *, XColor *);
|
||||
void draw_circle(DrawCtx *, int, int, int, Bool, XColor);
|
||||
void draw_graph(DrawCtx *, area_t, int *, int *, int, Position, area_t, xcolor_t *, xcolor_t *, xcolor_t *);
|
||||
void draw_graph_line(DrawCtx *, area_t, int *, int, Position, area_t, xcolor_t *, xcolor_t *, xcolor_t *);
|
||||
void draw_circle(DrawCtx *, int, int, int, bool, xcolor_t);
|
||||
void draw_image(DrawCtx *, int, int, int, const char *);
|
||||
void draw_image_from_argb_data(DrawCtx *, int, int, int, int, int, unsigned char *);
|
||||
area_t draw_get_image_size(const char *filename);
|
||||
void draw_rotate(DrawCtx *, Drawable, int, int, double, int, int);
|
||||
unsigned short draw_textwidth(Display *, font_t *, const char *);
|
||||
void draw_rotate(DrawCtx *, xcb_drawable_t, int, int, double, int, int);
|
||||
unsigned short draw_textwidth(xcb_connection_t *, int, font_t *, const char *);
|
||||
Alignment draw_align_get_from_str(const char *);
|
||||
Bool draw_color_new(Display *, int, const char *, XColor *);
|
||||
void draw_style_init(Display *, int, cfg_t *, style_t *, style_t *);
|
||||
bool draw_color_new(xcb_connection_t *, int, const char *, xcolor_t *);
|
||||
void draw_style_init(xcb_connection_t *, int, cfg_t *, style_t *, style_t *);
|
||||
|
||||
void area_list_remove(area_t **, area_t *);
|
||||
|
||||
|
|
104
common/swindow.c
104
common/swindow.c
|
@ -19,12 +19,14 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_aux.h>
|
||||
|
||||
#include "common/swindow.h"
|
||||
#include "common/util.h"
|
||||
|
||||
/** Create a simple window
|
||||
* \param disp Display ref
|
||||
* \param conn Connection ref
|
||||
* \param phys_screen physical screen id
|
||||
* \param x x coordinate
|
||||
* \param y y coordinate
|
||||
|
@ -34,12 +36,13 @@
|
|||
* \return pointer to a SimpleWindow
|
||||
*/
|
||||
SimpleWindow *
|
||||
simplewindow_new(Display *disp, int phys_screen, int x, int y,
|
||||
simplewindow_new(xcb_connection_t *conn, int phys_screen, int x, int y,
|
||||
unsigned int w, unsigned int h,
|
||||
unsigned int border_width)
|
||||
{
|
||||
XSetWindowAttributes wa;
|
||||
SimpleWindow *sw;
|
||||
xcb_screen_t *s = xcb_aux_get_screen(conn, phys_screen);
|
||||
uint32_t create_win_val[3];
|
||||
|
||||
sw = p_new(SimpleWindow, 1);
|
||||
|
||||
|
@ -47,30 +50,31 @@ simplewindow_new(Display *disp, int phys_screen, int x, int y,
|
|||
sw->geometry.y = y;
|
||||
sw->geometry.width = w;
|
||||
sw->geometry.height = h;
|
||||
sw->display = disp;
|
||||
sw->connection = conn;
|
||||
sw->phys_screen = phys_screen;
|
||||
|
||||
wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask
|
||||
| EnterWindowMask | LeaveWindowMask | StructureNotifyMask
|
||||
| ButtonPressMask | ExposureMask;
|
||||
wa.override_redirect = 1;
|
||||
wa.background_pixmap = ParentRelative;
|
||||
sw->window = XCreateWindow(disp,
|
||||
RootWindow(disp, phys_screen),
|
||||
x, y, w, h,
|
||||
border_width,
|
||||
DefaultDepth(disp, phys_screen),
|
||||
CopyFromParent,
|
||||
DefaultVisual(disp, phys_screen),
|
||||
CWOverrideRedirect | CWBackPixmap | CWEventMask,
|
||||
&wa);
|
||||
create_win_val[0] = XCB_BACK_PIXMAP_PARENT_RELATIVE;
|
||||
create_win_val[1] = 1;
|
||||
create_win_val[2] = XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
|
||||
XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_ENTER_WINDOW |
|
||||
XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_STRUCTURE_NOTIFY |
|
||||
XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_EXPOSURE;
|
||||
|
||||
XSelectInput(disp, sw->window, wa.event_mask);
|
||||
sw->window = xcb_generate_id(conn);
|
||||
xcb_create_window(conn, s->root_depth, sw->window,
|
||||
root_window(conn, phys_screen),
|
||||
x, y, w, h, border_width,
|
||||
XCB_COPY_FROM_PARENT,
|
||||
s->root_visual,
|
||||
XCB_CW_BACK_PIXMAP | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK,
|
||||
create_win_val);
|
||||
|
||||
x_select_input(conn, sw->window, create_win_val[2]);
|
||||
|
||||
sw->drawable = xcb_generate_id(conn);
|
||||
xcb_create_pixmap(conn, s->root_depth, sw->drawable,
|
||||
root_window(conn, phys_screen), w, h);
|
||||
|
||||
sw->drawable = XCreatePixmap(disp,
|
||||
RootWindow(disp, phys_screen),
|
||||
w, h,
|
||||
DefaultDepth(disp, phys_screen));
|
||||
return sw;
|
||||
}
|
||||
|
||||
|
@ -80,8 +84,8 @@ simplewindow_new(Display *disp, int phys_screen, int x, int y,
|
|||
void
|
||||
simplewindow_delete(SimpleWindow **sw)
|
||||
{
|
||||
XDestroyWindow((*sw)->display, (*sw)->window);
|
||||
XFreePixmap((*sw)->display, (*sw)->drawable);
|
||||
xcb_destroy_window((*sw)->connection, (*sw)->window);
|
||||
xcb_free_pixmap((*sw)->connection, (*sw)->drawable);
|
||||
p_delete(sw);
|
||||
}
|
||||
|
||||
|
@ -89,49 +93,63 @@ simplewindow_delete(SimpleWindow **sw)
|
|||
* \param sw the SimpleWindow to move
|
||||
* \param x x coordinate
|
||||
* \param y y coordinate
|
||||
* \return status
|
||||
*/
|
||||
int
|
||||
void
|
||||
simplewindow_move(SimpleWindow *sw, int x, int y)
|
||||
{
|
||||
const uint32_t move_win_vals[] = { x, y };
|
||||
|
||||
sw->geometry.x = x;
|
||||
sw->geometry.y = y;
|
||||
return XMoveWindow(sw->display, sw->window, x, y);
|
||||
xcb_configure_window(sw->connection, sw->window,
|
||||
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
|
||||
move_win_vals);
|
||||
}
|
||||
|
||||
/** Resize a simple window
|
||||
* \param sw the SimpleWindow to resize
|
||||
* \param w new width
|
||||
* \param h new height
|
||||
* \return status
|
||||
*/
|
||||
int
|
||||
void
|
||||
simplewindow_resize(SimpleWindow *sw, unsigned int w, unsigned int h)
|
||||
{
|
||||
xcb_screen_t *s = xcb_aux_get_screen(sw->connection, sw->phys_screen);
|
||||
const uint32_t resize_win_vals[] = { w, h };
|
||||
|
||||
sw->geometry.width = w;
|
||||
sw->geometry.height = h;
|
||||
XFreePixmap(sw->display, sw->drawable);
|
||||
sw->drawable = XCreatePixmap(sw->display,
|
||||
RootWindow(sw->display, sw->phys_screen),
|
||||
w, h,
|
||||
DefaultDepth(sw->display, sw->phys_screen));
|
||||
return XResizeWindow(sw->display, sw->window, w, h);
|
||||
xcb_free_pixmap(sw->connection, sw->drawable);
|
||||
sw->drawable = xcb_generate_id(sw->connection);
|
||||
xcb_create_pixmap(sw->connection, s->root_depth, sw->drawable,
|
||||
root_window(sw->connection, sw->phys_screen), w, h);
|
||||
xcb_configure_window(sw->connection, sw->window,
|
||||
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
|
||||
resize_win_vals);
|
||||
}
|
||||
|
||||
/** Refresh the window content
|
||||
* \param sw the SimpleWindow to refresh
|
||||
* \param phys_screen physical screen id
|
||||
* \return status
|
||||
*/
|
||||
int
|
||||
void
|
||||
simplewindow_refresh_drawable(SimpleWindow *sw, int phys_screen)
|
||||
{
|
||||
return XCopyArea(sw->display, sw->drawable,
|
||||
sw->window,
|
||||
DefaultGC(sw->display, phys_screen), 0, 0,
|
||||
xcb_screen_t *s = xcb_aux_get_screen(sw->connection, phys_screen);
|
||||
|
||||
/* The default GC is just a newly created associated to the root
|
||||
* window */
|
||||
xcb_drawable_t gc_draw = s->root;
|
||||
xcb_gcontext_t gc = xcb_generate_id(sw->connection);
|
||||
|
||||
const uint32_t gc_mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND;
|
||||
const uint32_t gc_values[2] = { s->black_pixel, s->white_pixel };
|
||||
|
||||
xcb_create_gc(sw->connection, gc, gc_draw, gc_mask, gc_values);
|
||||
xcb_copy_area(sw->connection, sw->drawable,
|
||||
sw->window, gc, 0, 0, 0, 0,
|
||||
sw->geometry.width,
|
||||
sw->geometry.height,
|
||||
0, 0);
|
||||
sw->geometry.height);
|
||||
}
|
||||
|
||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||
|
|
|
@ -27,25 +27,25 @@
|
|||
/** A simple window */
|
||||
typedef struct SimpleWindow
|
||||
{
|
||||
Display *display;
|
||||
xcb_connection_t *connection;
|
||||
int phys_screen;
|
||||
Window window;
|
||||
Drawable drawable;
|
||||
xcb_window_t window;
|
||||
xcb_drawable_t drawable;
|
||||
area_t geometry;
|
||||
} SimpleWindow;
|
||||
|
||||
SimpleWindow * simplewindow_new(Display *, int, int, int, unsigned int, unsigned int, unsigned int);
|
||||
SimpleWindow * simplewindow_new(xcb_connection_t *, int, int, int, unsigned int, unsigned int, unsigned int);
|
||||
void simplewindow_delete(SimpleWindow **);
|
||||
int simplewindow_move(SimpleWindow *, int, int);
|
||||
int simplewindow_resize(SimpleWindow *, unsigned int, unsigned int);
|
||||
int simplewindow_refresh_drawable(SimpleWindow *, int);
|
||||
void simplewindow_move(SimpleWindow *, int, int);
|
||||
void simplewindow_resize(SimpleWindow *, unsigned int, unsigned int);
|
||||
void simplewindow_refresh_drawable(SimpleWindow *, int);
|
||||
|
||||
static inline int
|
||||
static inline void
|
||||
simplewindow_move_resize(SimpleWindow *sw, int x, int y,
|
||||
unsigned int w, unsigned int h)
|
||||
{
|
||||
return (simplewindow_move(sw, x, y)
|
||||
&& simplewindow_resize(sw, w, h));
|
||||
simplewindow_move(sw, x, y);
|
||||
simplewindow_resize(sw, w, h);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -19,7 +19,9 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <X11/extensions/Xinerama.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_aux.h>
|
||||
#include <xcb/xinerama.h>
|
||||
|
||||
#include "common/xscreen.h"
|
||||
|
||||
|
@ -47,7 +49,7 @@ screen_get_bycoord(ScreensInfo *si, int screen, int x, int y)
|
|||
}
|
||||
|
||||
static inline area_t
|
||||
screen_xsitoarea(XineramaScreenInfo si)
|
||||
screen_xsitoarea(xcb_xinerama_screen_info_t si)
|
||||
{
|
||||
area_t a;
|
||||
|
||||
|
@ -67,33 +69,57 @@ screensinfo_delete(ScreensInfo **si)
|
|||
p_delete(si);
|
||||
}
|
||||
|
||||
static xcb_xinerama_screen_info_t *
|
||||
xinerama_query_screens(xcb_connection_t *c, int *screen_number)
|
||||
{
|
||||
xcb_xinerama_query_screens_reply_t *reply;
|
||||
xcb_xinerama_screen_info_t *si;
|
||||
|
||||
reply = xcb_xinerama_query_screens_reply(c,
|
||||
xcb_xinerama_query_screens_unchecked(c),
|
||||
NULL);
|
||||
|
||||
if(!reply)
|
||||
{
|
||||
*screen_number = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*screen_number = xcb_xinerama_query_screens_screen_info_length(reply);
|
||||
si = xcb_xinerama_query_screens_screen_info(reply);
|
||||
p_delete(&reply);
|
||||
|
||||
return si;
|
||||
}
|
||||
|
||||
ScreensInfo *
|
||||
screensinfo_new(Display *disp)
|
||||
screensinfo_new(xcb_connection_t *conn)
|
||||
{
|
||||
ScreensInfo *si;
|
||||
XineramaScreenInfo *xsi;
|
||||
xcb_xinerama_screen_info_t *xsi;
|
||||
int xinerama_screen_number, screen, screen_to_test;
|
||||
Bool drop;
|
||||
xcb_screen_t *s;
|
||||
bool drop;
|
||||
|
||||
si = p_new(ScreensInfo, 1);
|
||||
|
||||
if((si->xinerama_is_active = XineramaIsActive(disp)))
|
||||
if((si->xinerama_is_active = xinerama_is_active(conn)))
|
||||
{
|
||||
xsi = XineramaQueryScreens(disp, &xinerama_screen_number);
|
||||
xsi = xinerama_query_screens(conn, &xinerama_screen_number);
|
||||
si->geometry = p_new(area_t, xinerama_screen_number);
|
||||
si->nscreen = 0;
|
||||
|
||||
/* now check if screens overlaps (same x,y): if so, we take only the biggest one */
|
||||
for(screen = 0; screen < xinerama_screen_number; screen++)
|
||||
{
|
||||
drop = False;
|
||||
drop = false;
|
||||
for(screen_to_test = 0; screen_to_test < si->nscreen; screen_to_test++)
|
||||
if(xsi[screen].x_org == si->geometry[screen_to_test].x
|
||||
&& xsi[screen].y_org == si->geometry[screen_to_test].y)
|
||||
{
|
||||
/* we already have a screen for this area, just check if
|
||||
* it's not bigger and drop it */
|
||||
drop = True;
|
||||
drop = true;
|
||||
si->geometry[screen_to_test].width =
|
||||
MAX(xsi[screen].width, xsi[screen_to_test].width);
|
||||
si->geometry[screen_to_test].height =
|
||||
|
@ -112,18 +138,19 @@ screensinfo_new(Display *disp)
|
|||
si->geometry = newgeometry;
|
||||
}
|
||||
|
||||
XFree(xsi);
|
||||
p_delete(&xsi);
|
||||
}
|
||||
else
|
||||
{
|
||||
si->nscreen = ScreenCount(disp);
|
||||
si->nscreen = xcb_setup_roots_length(xcb_get_setup(conn));
|
||||
si->geometry = p_new(area_t, si->nscreen);
|
||||
for(screen = 0; screen < si->nscreen; screen++)
|
||||
{
|
||||
s = xcb_aux_get_screen(conn, screen);
|
||||
si->geometry[screen].x = 0;
|
||||
si->geometry[screen].y = 0;
|
||||
si->geometry[screen].width = DisplayWidth(disp, screen);
|
||||
si->geometry[screen].height = DisplayHeight(disp, screen);
|
||||
si->geometry[screen].width = s->width_in_pixels;
|
||||
si->geometry[screen].height = s->height_in_pixels;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,13 +27,13 @@
|
|||
typedef struct
|
||||
{
|
||||
int nscreen;
|
||||
Bool xinerama_is_active;
|
||||
bool xinerama_is_active;
|
||||
area_t *geometry;
|
||||
} ScreensInfo;
|
||||
|
||||
int screen_get_bycoord(ScreensInfo *, int, int, int);
|
||||
void screensinfo_delete(ScreensInfo **);
|
||||
ScreensInfo * screensinfo_new(Display *);
|
||||
ScreensInfo * screensinfo_new(xcb_connection_t *);
|
||||
|
||||
#endif
|
||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||
|
|
202
common/xutil.c
202
common/xutil.c
|
@ -19,60 +19,208 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/Xatom.h>
|
||||
/* strndup() */
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_aux.h>
|
||||
#include <xcb/xcb_atom.h>
|
||||
#include <xcb/xinerama.h>
|
||||
#include <xcb/xcb_keysyms.h>
|
||||
|
||||
#include "common/util.h"
|
||||
#include "common/xutil.h"
|
||||
|
||||
Bool
|
||||
xgettextprop(Display *disp, Window w, Atom atom, char *text, ssize_t textlen)
|
||||
bool
|
||||
xgettextprop(xcb_connection_t *conn, xcb_window_t w, xcb_atom_t atom,
|
||||
char *text, ssize_t textlen)
|
||||
{
|
||||
char **list = NULL;
|
||||
int n;
|
||||
XTextProperty name;
|
||||
xcb_get_property_reply_t *name = NULL;
|
||||
char *prop_val = NULL;
|
||||
|
||||
if(!text || !textlen)
|
||||
return False;
|
||||
return false;
|
||||
|
||||
text[0] = '\0';
|
||||
XGetTextProperty(disp, w, &name, atom);
|
||||
name = xcb_get_property_reply(conn,
|
||||
xcb_get_property_unchecked(conn, false,
|
||||
w, atom,
|
||||
XCB_GET_PROPERTY_TYPE_ANY,
|
||||
0L, 1000000L),
|
||||
NULL);
|
||||
|
||||
if(!name.nitems)
|
||||
return False;
|
||||
if(!name->value_len)
|
||||
return false;
|
||||
|
||||
if(name.encoding == XA_STRING)
|
||||
a_strncpy(text, textlen, (char *) name.value, textlen - 1);
|
||||
prop_val = (char *) xcb_get_property_value(name);
|
||||
if(name->type == STRING)
|
||||
a_strncpy(text, textlen, prop_val, textlen - 1);
|
||||
|
||||
else if(XmbTextPropertyToTextList(disp, &name, &list, &n) >= Success && n > 0 && *list)
|
||||
{
|
||||
a_strncpy(text, textlen, *list, textlen - 1);
|
||||
XFreeStringList(list);
|
||||
}
|
||||
/* TODO: XCB doesn't provide a XmbTextPropertyToTextList(), check
|
||||
* whether this code is correct (locales) */
|
||||
else if(name->format == 8)
|
||||
a_strncpy(text, textlen, prop_val, textlen - 1);
|
||||
|
||||
text[textlen - 1] = '\0';
|
||||
XFree(name.value);
|
||||
p_delete(&name);
|
||||
|
||||
return True;
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
xgetnumlockmask(Display *disp)
|
||||
xgetnumlockmask(xcb_connection_t *conn)
|
||||
{
|
||||
XModifierKeymap *modmap;
|
||||
xcb_get_modifier_mapping_reply_t *modmap_r;
|
||||
xcb_keycode_t *modmap;
|
||||
xcb_key_symbols_t *keysyms = xcb_key_symbols_alloc(conn);
|
||||
unsigned int mask = 0;
|
||||
int i, j;
|
||||
|
||||
modmap = XGetModifierMapping(disp);
|
||||
modmap_r = xcb_get_modifier_mapping_reply(conn,
|
||||
xcb_get_modifier_mapping_unchecked(conn),
|
||||
NULL);
|
||||
|
||||
modmap = xcb_get_modifier_mapping_keycodes(modmap_r);
|
||||
|
||||
for(i = 0; i < 8; i++)
|
||||
for(j = 0; j < modmap->max_keypermod; j++)
|
||||
if(modmap->modifiermap[i * modmap->max_keypermod + j]
|
||||
== XKeysymToKeycode(disp, XK_Num_Lock))
|
||||
for(j = 0; j < modmap_r->keycodes_per_modifier; j++)
|
||||
if(modmap[i * modmap_r->keycodes_per_modifier + j]
|
||||
== xcb_key_symbols_get_keycode(keysyms, XK_Num_Lock))
|
||||
mask = (1 << i);
|
||||
|
||||
XFreeModifiermap(modmap);
|
||||
p_delete(&modmap_r);
|
||||
xcb_key_symbols_free(keysyms);
|
||||
|
||||
return mask;
|
||||
}
|
||||
|
||||
/** 'XSelectInput' from Xlib is only a function around
|
||||
* 'ChangeWindowAttributes' which set the value mask to 'CWEventMask'
|
||||
* \param c X connection
|
||||
*/
|
||||
void
|
||||
x_select_input(xcb_connection_t *c, xcb_window_t w,
|
||||
uint32_t event_mask)
|
||||
{
|
||||
const uint32_t config_win_val[] = { event_mask };
|
||||
xcb_change_window_attributes_checked(c, w, XCB_CW_EVENT_MASK, config_win_val);
|
||||
}
|
||||
|
||||
/** Equivalent to 'XGetTransientForHint' which is actually a
|
||||
* 'XGetWindowProperty' which gets the WM_TRANSIENT_FOR property of
|
||||
* the specified window
|
||||
*
|
||||
* \param c X connection
|
||||
* \param win get the property from this window
|
||||
* \param prop_win returns the WM_TRANSIENT_FOR property of win
|
||||
* \return return true if successfull
|
||||
*/
|
||||
bool
|
||||
x_get_transient_for_hint(xcb_connection_t *c, xcb_window_t win,
|
||||
xcb_window_t *prop_win)
|
||||
{
|
||||
xcb_get_property_reply_t *r;
|
||||
|
||||
/* Use checked because the error handler should not take care of
|
||||
* this error as we only return a boolean */
|
||||
r = xcb_get_property_reply(c,
|
||||
xcb_get_property(c, false, win,
|
||||
WM_TRANSIENT_FOR,
|
||||
WINDOW, 0, 1),
|
||||
NULL);
|
||||
|
||||
if(!r)
|
||||
return false;
|
||||
|
||||
*prop_win = *((xcb_window_t *) xcb_get_property_value(r));
|
||||
p_delete(&r);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
xinerama_is_active(xcb_connection_t *c)
|
||||
{
|
||||
bool ret;
|
||||
xcb_xinerama_is_active_reply_t *r = NULL;
|
||||
|
||||
r = xcb_xinerama_is_active_reply(c, xcb_xinerama_is_active(c), NULL);
|
||||
if(!r)
|
||||
return false;
|
||||
|
||||
ret = r->state;
|
||||
p_delete(&r);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
xcb_window_t
|
||||
root_window(xcb_connection_t *c, int screen_number)
|
||||
{
|
||||
return xcb_aux_get_screen(c, screen_number)->root;
|
||||
}
|
||||
|
||||
xcb_atom_t
|
||||
x_intern_atom(xcb_connection_t *c, const char *property)
|
||||
{
|
||||
xcb_atom_t atom;
|
||||
xcb_intern_atom_reply_t *r_atom;
|
||||
|
||||
r_atom = xcb_intern_atom_reply(c,
|
||||
xcb_intern_atom_unchecked(c, false, strlen(property), property),
|
||||
NULL);
|
||||
|
||||
if(!r_atom)
|
||||
return 0;
|
||||
|
||||
atom = r_atom->atom;
|
||||
p_delete(&r_atom);
|
||||
|
||||
return atom;
|
||||
}
|
||||
|
||||
class_hint_t *
|
||||
x_get_class_hint(xcb_connection_t *conn, xcb_window_t win)
|
||||
{
|
||||
xcb_get_property_reply_t *r = NULL;
|
||||
char *data = NULL;
|
||||
|
||||
int len_name, len_class;
|
||||
|
||||
class_hint_t *ch = p_new(class_hint_t, 1);
|
||||
|
||||
/* TODO: 2048? (BUFINC is declared as private in xcb.c) */
|
||||
r = xcb_get_property_reply(conn,
|
||||
xcb_get_property_unchecked(conn,
|
||||
false, win, WM_CLASS,
|
||||
STRING, 0L, 2048),
|
||||
NULL);
|
||||
|
||||
if(!r || r->type != STRING || r->format == 8)
|
||||
return NULL;
|
||||
|
||||
data = xcb_get_property_value(r);
|
||||
|
||||
len_name = strlen((char *) data);
|
||||
len_class = strlen((char *) (data + len_name + 1));
|
||||
|
||||
ch->res_name = strndup(data, len_name);
|
||||
ch->res_class = strndup(data + len_name + 1, len_class);
|
||||
|
||||
p_delete(&r);
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
void
|
||||
xutil_map_raised(xcb_connection_t *conn, xcb_window_t win)
|
||||
{
|
||||
const uint32_t map_raised_val = XCB_STACK_MODE_ABOVE;
|
||||
|
||||
xcb_configure_window(conn, win, XCB_CONFIG_WINDOW_STACK_MODE,
|
||||
&map_raised_val);
|
||||
|
||||
xcb_map_window(conn, win);
|
||||
}
|
||||
|
||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||
|
|
|
@ -22,10 +22,91 @@
|
|||
#ifndef AWESOME_COMMON_XUTIL_H
|
||||
#define AWESOME_COMMON_XUTIL_H
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
Bool xgettextprop(Display *, Window, Atom, char *, ssize_t);
|
||||
unsigned int xgetnumlockmask(Display *);
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
/* XCB doesn't provide keysyms definition */
|
||||
#include <X11/keysym.h>
|
||||
|
||||
bool xgettextprop(xcb_connection_t *, xcb_window_t, xcb_atom_t, char *, ssize_t);
|
||||
unsigned int xgetnumlockmask(xcb_connection_t *);
|
||||
|
||||
/* See http://tronche.com/gui/x/xlib/appendix/b/ for values */
|
||||
#define CURSOR_FLEUR 52
|
||||
#define CURSOR_LEFT_PTR 68
|
||||
#define CURSOR_SIZING 120
|
||||
|
||||
#define ANY_KEY 0L /* special Key Code, passed to GrabKey */
|
||||
#define ANY_MODIFIER (1<<15) /* used in GrabButton, GrabKey */
|
||||
|
||||
/*****************************************************************
|
||||
* ERROR CODES
|
||||
*****************************************************************/
|
||||
|
||||
#define Success 0 /* everything's okay */
|
||||
#define BadRequest 1 /* bad request code */
|
||||
#define BadValue 2 /* int parameter out of range */
|
||||
#define BadWindow 3 /* parameter not a Window */
|
||||
#define BadPixmap 4 /* parameter not a Pixmap */
|
||||
#define BadAtom 5 /* parameter not an Atom */
|
||||
#define BadCursor 6 /* parameter not a Cursor */
|
||||
#define BadFont 7 /* parameter not a Font */
|
||||
#define BadMatch 8 /* parameter mismatch */
|
||||
#define BadDrawable 9 /* parameter not a Pixmap or Window */
|
||||
#define BadAccess 10 /* depending on context:
|
||||
- key/button already grabbed
|
||||
- attempt to free an illegal
|
||||
cmap entry
|
||||
- attempt to store into a read-only
|
||||
color map entry.
|
||||
- attempt to modify the access control
|
||||
list from other than the local host.
|
||||
*/
|
||||
#define BadAlloc 11 /* insufficient resources */
|
||||
#define BadColor 12 /* no such colormap */
|
||||
#define BadGC 13 /* parameter not a GC */
|
||||
#define BadIDChoice 14 /* choice not in range or already used */
|
||||
#define BadName 15 /* font or color name doesn't exist */
|
||||
#define BadLength 16 /* Request length incorrect */
|
||||
#define BadImplementation 17 /* server is defective */
|
||||
|
||||
#define FirstExtensionError 128
|
||||
#define LastExtensionError 255
|
||||
/* End of macros not defined in XCB */
|
||||
|
||||
/* Common function defined in Xlib but not in XCB */
|
||||
void x_select_input(xcb_connection_t *, xcb_window_t, uint32_t);
|
||||
bool x_get_transient_for_hint(xcb_connection_t *, xcb_window_t, xcb_window_t *);
|
||||
bool xinerama_is_active(xcb_connection_t *);
|
||||
xcb_window_t root_window(xcb_connection_t *, int);
|
||||
|
||||
typedef struct _class_hint_t
|
||||
{
|
||||
char *res_name;
|
||||
char *res_class;
|
||||
} class_hint_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t pixel;
|
||||
uint16_t red;
|
||||
uint16_t green;
|
||||
uint16_t blue;
|
||||
} xcolor_t;
|
||||
|
||||
class_hint_t *x_get_class_hint(xcb_connection_t *, xcb_window_t);
|
||||
|
||||
/* Equivalent call to XInternAtom
|
||||
*
|
||||
* WARNING: should not be used in loop, in this case, it should send
|
||||
* the queries first and then treat the answer as late as possible)
|
||||
*/
|
||||
xcb_atom_t x_intern_atom(xcb_connection_t *, const char *);
|
||||
|
||||
/* Equivalent XCB call to XMapRaised, which actually raises the
|
||||
specified window to the top of the stack and maps it */
|
||||
void xutil_map_raised(xcb_connection_t *, xcb_window_t);
|
||||
|
||||
#endif
|
||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||
|
|
80
config.c
80
config.c
|
@ -19,8 +19,11 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/* XStringToKeysym() */
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
#include <xcb/xcb_keysyms.h>
|
||||
#include <errno.h>
|
||||
#include <X11/keysym.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "statusbar.h"
|
||||
|
@ -34,11 +37,11 @@
|
|||
#include "common/xutil.h"
|
||||
|
||||
/* Permit to use mouse with many more buttons */
|
||||
#ifndef Button6
|
||||
#define Button6 6
|
||||
#ifndef XCB_BUTTON_INDEX_6
|
||||
#define XCB_BUTTON_INDEX_6 6
|
||||
#endif
|
||||
#ifndef Button7
|
||||
#define Button7 7
|
||||
#ifndef XCB_BUTTON_INDEX_7
|
||||
#define XCB_BUTTON_INDEX_7 7
|
||||
#endif
|
||||
|
||||
extern AwesomeConf globalconf;
|
||||
|
@ -48,7 +51,7 @@ extern cfg_opt_t awesome_opts[];
|
|||
typedef struct
|
||||
{
|
||||
const char *name;
|
||||
KeySym keysym;
|
||||
xcb_keysym_t keysym;
|
||||
} KeyMod;
|
||||
|
||||
/** Link a name to a mouse button symbol */
|
||||
|
@ -67,21 +70,21 @@ extern const name_func_link_t FloatingPlacementList[];
|
|||
* \param keyname Key name
|
||||
* \return Key mask or 0 if not found
|
||||
*/
|
||||
static KeySym
|
||||
static xcb_keysym_t
|
||||
key_mask_lookup(const char *keyname)
|
||||
{
|
||||
/** List of keyname and corresponding X11 mask codes */
|
||||
static const KeyMod KeyModList[] =
|
||||
{
|
||||
{"Shift", ShiftMask},
|
||||
{"Lock", LockMask},
|
||||
{"Control", ControlMask},
|
||||
{"Mod1", Mod1Mask},
|
||||
{"Mod2", Mod2Mask},
|
||||
{"Mod3", Mod3Mask},
|
||||
{"Mod4", Mod4Mask},
|
||||
{"Mod5", Mod5Mask},
|
||||
{NULL, NoSymbol}
|
||||
{"Shift", XCB_MOD_MASK_SHIFT},
|
||||
{"Lock", XCB_MOD_MASK_LOCK},
|
||||
{"Control", XCB_MOD_MASK_CONTROL},
|
||||
{"Mod1", XCB_MOD_MASK_1},
|
||||
{"Mod2", XCB_MOD_MASK_2},
|
||||
{"Mod3", XCB_MOD_MASK_3},
|
||||
{"Mod4", XCB_MOD_MASK_4},
|
||||
{"Mod5", XCB_MOD_MASK_5},
|
||||
{NULL, XCB_NO_SYMBOL}
|
||||
};
|
||||
int i;
|
||||
|
||||
|
@ -103,13 +106,13 @@ mouse_button_lookup(const char *button)
|
|||
/** List of button name and corresponding X11 mask codes */
|
||||
static const MouseButton MouseButtonList[] =
|
||||
{
|
||||
{"1", Button1},
|
||||
{"2", Button2},
|
||||
{"3", Button3},
|
||||
{"4", Button4},
|
||||
{"5", Button5},
|
||||
{"6", Button6},
|
||||
{"7", Button7},
|
||||
{"1", XCB_BUTTON_INDEX_1},
|
||||
{"2", XCB_BUTTON_INDEX_2},
|
||||
{"3", XCB_BUTTON_INDEX_3},
|
||||
{"4", XCB_BUTTON_INDEX_4},
|
||||
{"5", XCB_BUTTON_INDEX_5},
|
||||
{"6", XCB_BUTTON_INDEX_6},
|
||||
{"7", XCB_BUTTON_INDEX_7},
|
||||
{NULL, 0}
|
||||
};
|
||||
int i;
|
||||
|
@ -123,7 +126,7 @@ mouse_button_lookup(const char *button)
|
|||
}
|
||||
|
||||
static Button *
|
||||
parse_mouse_bindings(cfg_t * cfg, const char *secname, Bool handle_arg)
|
||||
parse_mouse_bindings(cfg_t * cfg, const char *secname, bool handle_arg)
|
||||
{
|
||||
int i, j;
|
||||
cfg_t *cfgsectmp;
|
||||
|
@ -168,7 +171,8 @@ set_key_info(Key *key, cfg_t *cfg)
|
|||
static void
|
||||
config_key_store(Key *key, char *str)
|
||||
{
|
||||
KeyCode kc;
|
||||
xcb_keycode_t kc;
|
||||
xcb_keysym_t ks;
|
||||
int ikc;
|
||||
|
||||
if(!a_strlen(str))
|
||||
|
@ -269,7 +273,7 @@ statusbar_widgets_create(cfg_t *cfg_statusbar, Statusbar *statusbar)
|
|||
widget = widget_new(statusbar, wptr);
|
||||
widget_list_append(&statusbar->widgets, widget);
|
||||
widget->buttons = parse_mouse_bindings(wptr, "mouse",
|
||||
a_strcmp(cfg_name(wptr), "taglist") ? True : False);
|
||||
a_strcmp(cfg_name(wptr), "taglist") ? true : false);
|
||||
}
|
||||
else
|
||||
warn("ignoring unknown widget: %s.\n", cfg_name(widgets + i));
|
||||
|
@ -288,15 +292,15 @@ config_section_titlebar_init(cfg_t *cfg_titlebar, Titlebar *tb, int screen)
|
|||
tb->text_align = cfg_getalignment(cfg_titlebar, "text_align");
|
||||
tb->width = cfg_getint(cfg_titlebar, "width");
|
||||
tb->height = cfg_getint(cfg_titlebar, "height");
|
||||
draw_style_init(globalconf.display, phys_screen,
|
||||
draw_style_init(globalconf.connection, phys_screen,
|
||||
cfg_getsec(cfg_styles, "normal"),
|
||||
&tb->styles.normal,
|
||||
&globalconf.screens[screen].styles.normal);
|
||||
draw_style_init(globalconf.display, phys_screen,
|
||||
draw_style_init(globalconf.connection, phys_screen,
|
||||
cfg_getsec(cfg_styles, "focus"),
|
||||
&tb->styles.focus,
|
||||
&globalconf.screens[screen].styles.focus);
|
||||
draw_style_init(globalconf.display, phys_screen,
|
||||
draw_style_init(globalconf.connection, phys_screen,
|
||||
cfg_getsec(cfg_styles, "urgent"),
|
||||
&tb->styles.urgent,
|
||||
&globalconf.screens[screen].styles.urgent);
|
||||
|
@ -378,11 +382,11 @@ config_parse_screen(cfg_t *cfg, int screen)
|
|||
if(!(cfg_styles_urgent = cfg_getsec(cfg_styles, "urgent")))
|
||||
eprint("no urgent colors section found\n");
|
||||
|
||||
draw_style_init(globalconf.display, phys_screen,
|
||||
draw_style_init(globalconf.connection, phys_screen,
|
||||
cfg_styles_normal, &virtscreen->styles.normal, NULL);
|
||||
draw_style_init(globalconf.display, phys_screen,
|
||||
draw_style_init(globalconf.connection, phys_screen,
|
||||
cfg_styles_focus, &virtscreen->styles.focus, &virtscreen->styles.normal);
|
||||
draw_style_init(globalconf.display, phys_screen,
|
||||
draw_style_init(globalconf.connection, phys_screen,
|
||||
cfg_styles_urgent, &virtscreen->styles.urgent, &virtscreen->styles.normal);
|
||||
|
||||
if(!virtscreen->styles.normal.font)
|
||||
|
@ -464,8 +468,8 @@ config_parse_screen(cfg_t *cfg, int screen)
|
|||
}
|
||||
|
||||
/* select first tag by default */
|
||||
virtscreen->tags[0].selected = True;
|
||||
virtscreen->tags[0].was_selected = True;
|
||||
virtscreen->tags[0].selected = true;
|
||||
virtscreen->tags[0].was_selected = true;
|
||||
|
||||
/* padding */
|
||||
virtscreen->padding.top = cfg_getint(cfg_padding, "top");
|
||||
|
@ -549,16 +553,16 @@ config_parse(const char *confpatharg)
|
|||
}
|
||||
|
||||
/* Mouse: root window click bindings */
|
||||
globalconf.buttons.root = parse_mouse_bindings(cfg_mouse, "root", True);
|
||||
globalconf.buttons.root = parse_mouse_bindings(cfg_mouse, "root", true);
|
||||
|
||||
/* Mouse: client windows click bindings */
|
||||
globalconf.buttons.client = parse_mouse_bindings(cfg_mouse, "client", True);
|
||||
globalconf.buttons.client = parse_mouse_bindings(cfg_mouse, "client", true);
|
||||
|
||||
/* Mouse: titlebar windows click bindings */
|
||||
globalconf.buttons.titlebar = parse_mouse_bindings(cfg_mouse, "titlebar", True);
|
||||
globalconf.buttons.titlebar = parse_mouse_bindings(cfg_mouse, "titlebar", true);
|
||||
|
||||
/* Keys */
|
||||
globalconf.numlockmask = xgetnumlockmask(globalconf.display);
|
||||
globalconf.numlockmask = xgetnumlockmask(globalconf.connection);
|
||||
|
||||
globalconf.keys = section_keys(cfg_keys);
|
||||
|
||||
|
|
25
configure.ac
25
configure.ac
|
@ -113,10 +113,6 @@ PKG_CHECK_MODULES([pangocairo], [pangocairo],,
|
|||
[AC_MSG_ERROR([awesome requires pangocairo.])])
|
||||
PKG_CHECK_MODULES([confuse], [libconfuse >= 2.6],,
|
||||
[AC_MSG_ERROR([awesome requires libconfuse >= 2.6.])])
|
||||
PKG_CHECK_MODULES([xinerama], [xinerama],,
|
||||
[AC_MSG_ERROR([awesome requires Xinerama.])])
|
||||
PKG_CHECK_MODULES([xrandr], [xrandr],,
|
||||
[AC_MSG_ERROR([awesome requires Xrandr.])])
|
||||
AC_ARG_WITH([gtk], AS_HELP_STRING([--with-gtk], [Build with gtk library (default: disabled)]))
|
||||
|
||||
if test "x$with_gtk" == "xyes"; then
|
||||
|
@ -127,9 +123,28 @@ else
|
|||
PKG_CHECK_MODULES([imlib2], [imlib2],,
|
||||
[AC_MSG_ERROR([awesome requires Imlib2.])])
|
||||
fi
|
||||
PKG_CHECK_MODULES([xcb], [xcb],,
|
||||
[AC_MSG_ERROR([awesome requires xcb.])])
|
||||
PKG_CHECK_MODULES([xcb_event], [xcb-event],,
|
||||
[AC_MSG_ERROR([awesome requires xcb-event.])])
|
||||
PKG_CHECK_MODULES([xcb_randr], [xcb-randr],,
|
||||
[AC_MSG_ERROR([awesome requires xcb-randr.])])
|
||||
PKG_CHECK_MODULES([xcb_xinerama], [xcb-xinerama],,
|
||||
[AC_MSG_ERROR([awesome requires xcb-xinerama.])])
|
||||
PKG_CHECK_MODULES([xcb_shape], [xcb-shape],,
|
||||
[AC_MSG_ERROR([awesome requires xcb-shape.])])
|
||||
PKG_CHECK_MODULES([xcb_aux], [xcb-aux],,
|
||||
[AC_MSG_ERROR([awesome requires xcb-aux.])])
|
||||
PKG_CHECK_MODULES([xcb_atom], [xcb-atom],,
|
||||
[AC_MSG_ERROR([awesome requires xcb-atom.])])
|
||||
PKG_CHECK_MODULES([xcb_keysyms], [xcb-keysyms],,
|
||||
[AC_MSG_ERROR([awesome requires xcb-keysyms.])])
|
||||
PKG_CHECK_MODULES([xcb_render], [xcb-render],,
|
||||
[AC_MSG_ERROR([awesome requires xcb-render.])])
|
||||
PKG_CHECK_MODULES([xcb_icccm], [xcb-icccm],,
|
||||
[AC_MSG_ERROR([awesome requires xcb-icccm.])])
|
||||
|
||||
# Checks for header files.
|
||||
AC_PATH_X
|
||||
AC_HEADER_STDC
|
||||
AC_HEADER_SYS_WAIT
|
||||
AC_CHECK_HEADERS([fcntl.h limits.h locale.h stdlib.h string.h sys/socket.h unistd.h])
|
||||
|
|
451
event.c
451
event.c
|
@ -19,11 +19,12 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <X11/keysym.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/extensions/shape.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include <xcb/xcb_keysyms.h>
|
||||
#include <xcb/xcb_icccm.h>
|
||||
#include <xcb/xcb_atom.h>
|
||||
#include <xcb/xcb_aux.h>
|
||||
#include <xcb/shape.h>
|
||||
#include <xcb/randr.h>
|
||||
|
||||
#include "screen.h"
|
||||
#include "event.h"
|
||||
|
@ -39,6 +40,7 @@
|
|||
#include "layouts/tile.h"
|
||||
#include "layouts/floating.h"
|
||||
#include "common/xscreen.h"
|
||||
#include "common/xutil.h"
|
||||
|
||||
extern AwesomeConf globalconf;
|
||||
|
||||
|
@ -66,139 +68,140 @@ event_handle_mouse_button_press(int screen, unsigned int button, unsigned int st
|
|||
}
|
||||
|
||||
/** Handle XButtonPressed events
|
||||
* \param e XEvent
|
||||
* \param connection connection to the X server
|
||||
* \param ev ButtonPress event
|
||||
*/
|
||||
void
|
||||
event_handle_buttonpress(XEvent *e)
|
||||
int
|
||||
event_handle_buttonpress(void *data __attribute__ ((unused)),
|
||||
xcb_connection_t *connection, xcb_button_press_event_t *ev)
|
||||
{
|
||||
int i, screen, x = 0, y = 0;
|
||||
unsigned int udummy;
|
||||
int screen;
|
||||
Client *c;
|
||||
Window wdummy;
|
||||
Widget *widget;
|
||||
Statusbar *statusbar;
|
||||
XButtonPressedEvent *ev = &e->xbutton;
|
||||
xcb_query_pointer_reply_t *qr;
|
||||
|
||||
for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
|
||||
for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next)
|
||||
if(statusbar->sw->window == ev->window || statusbar->sw->window == ev->subwindow)
|
||||
if(statusbar->sw->window == ev->event || statusbar->sw->window == ev->child)
|
||||
{
|
||||
switch(statusbar->position)
|
||||
{
|
||||
case Top:
|
||||
case Bottom:
|
||||
for(widget = statusbar->widgets; widget; widget = widget->next)
|
||||
if(ev->x >= widget->area.x && ev->x < widget->area.x + widget->area.width
|
||||
&& ev->y >= widget->area.y && ev->y < widget->area.y + widget->area.height)
|
||||
if(ev->event_x >= widget->area.x && ev->event_x < widget->area.x + widget->area.width
|
||||
&& ev->event_y >= widget->area.y && ev->event_y < widget->area.y + widget->area.height)
|
||||
{
|
||||
widget->button_press(widget, ev);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case Right:
|
||||
for(widget = statusbar->widgets; widget; widget = widget->next)
|
||||
if(ev->y >= widget->area.x && ev->y < widget->area.x + widget->area.width
|
||||
&& statusbar->sw->geometry.width - ev->x >= widget->area.y
|
||||
&& statusbar->sw->geometry.width - ev->x
|
||||
if(ev->event_y >= widget->area.x && ev->event_y < widget->area.x + widget->area.width
|
||||
&& statusbar->sw->geometry.width - ev->event_x >= widget->area.y
|
||||
&& statusbar->sw->geometry.width - ev->event_x
|
||||
< widget->area.y + widget->area.height)
|
||||
{
|
||||
widget->button_press(widget, ev);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case Left:
|
||||
for(widget = statusbar->widgets; widget; widget = widget->next)
|
||||
if(statusbar->sw->geometry.height - ev->y >= widget->area.x
|
||||
&& statusbar->sw->geometry.height - ev->y
|
||||
if(statusbar->sw->geometry.height - ev->event_y >= widget->area.x
|
||||
&& statusbar->sw->geometry.height - ev->event_y
|
||||
< widget->area.x + widget->area.width
|
||||
&& ev->x >= widget->area.y && ev->x < widget->area.y + widget->area.height)
|
||||
&& ev->event_x >= widget->area.y && ev->event_x < widget->area.y + widget->area.height)
|
||||
{
|
||||
widget->button_press(widget, ev);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
/* return if no widget match */
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(c = globalconf.clients; c; c = c->next)
|
||||
if(c->titlebar.sw && c->titlebar.sw->window == ev->window)
|
||||
if(c->titlebar.sw && c->titlebar.sw->window == ev->event)
|
||||
{
|
||||
if(!client_focus(c, c->screen, True))
|
||||
if(!client_focus(c, c->screen, true))
|
||||
client_stack(c);
|
||||
if(CLEANMASK(ev->state) == NoSymbol
|
||||
&& ev->button == Button1)
|
||||
if(CLEANMASK(ev->state) == XCB_NO_SYMBOL
|
||||
&& ev->detail == XCB_BUTTON_INDEX_1)
|
||||
window_grabbuttons(c->win, c->phys_screen);
|
||||
event_handle_mouse_button_press(c->screen, ev->button, ev->state,
|
||||
event_handle_mouse_button_press(c->screen, ev->detail, ev->state,
|
||||
globalconf.buttons.titlebar, NULL);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if((c = client_get_bywin(globalconf.clients, ev->window)))
|
||||
if((c = client_get_bywin(globalconf.clients, ev->event)))
|
||||
{
|
||||
if(!client_focus(c, c->screen, True))
|
||||
if(!client_focus(c, c->screen, true))
|
||||
client_stack(c);
|
||||
if(CLEANMASK(ev->state) == NoSymbol
|
||||
&& ev->button == Button1)
|
||||
if(CLEANMASK(ev->state) == XCB_NO_SYMBOL
|
||||
&& ev->detail == XCB_BUTTON_INDEX_1)
|
||||
{
|
||||
XAllowEvents(globalconf.display, ReplayPointer, CurrentTime);
|
||||
xcb_allow_events(globalconf.connection, XCB_ALLOW_REPLAY_POINTER, XCB_CURRENT_TIME);
|
||||
window_grabbuttons(c->win, c->phys_screen);
|
||||
}
|
||||
else
|
||||
event_handle_mouse_button_press(c->screen, ev->button, ev->state, globalconf.buttons.client, NULL);
|
||||
event_handle_mouse_button_press(c->screen, ev->detail, ev->state, globalconf.buttons.client, NULL);
|
||||
}
|
||||
else
|
||||
for(screen = 0; screen < xcb_setup_roots_length(xcb_get_setup (connection)); screen++)
|
||||
if(root_window(connection, screen) == ev->event
|
||||
&& (qr = xcb_query_pointer_reply(connection,
|
||||
xcb_query_pointer(connection, ev->event),
|
||||
NULL)) != NULL)
|
||||
{
|
||||
for(screen = 0; screen < ScreenCount(e->xany.display); screen++)
|
||||
if(RootWindow(e->xany.display, screen) == ev->window
|
||||
&& XQueryPointer(e->xany.display,
|
||||
ev->window, &wdummy,
|
||||
&wdummy, &x, &y, &i,
|
||||
&i, &udummy))
|
||||
{
|
||||
screen = screen_get_bycoord(globalconf.screens_info, screen, x, y);
|
||||
event_handle_mouse_button_press(screen, ev->button, ev->state,
|
||||
screen = screen_get_bycoord(globalconf.screens_info, screen, qr->root_x, qr->root_y);
|
||||
event_handle_mouse_button_press(screen, ev->detail, ev->state,
|
||||
globalconf.buttons.root, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
p_delete(&qr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Handle XConfigureRequest events
|
||||
* \param e XEvent
|
||||
* \param connection connection to the X server
|
||||
* \param ev ConfigureRequest event
|
||||
*/
|
||||
void
|
||||
event_handle_configurerequest(XEvent * e)
|
||||
int
|
||||
event_handle_configurerequest(void *data __attribute__ ((unused)),
|
||||
xcb_connection_t *connection, xcb_configure_request_event_t *ev)
|
||||
{
|
||||
Client *c;
|
||||
XConfigureRequestEvent *ev = &e->xconfigurerequest;
|
||||
XWindowChanges wc;
|
||||
area_t geometry;
|
||||
|
||||
if((c = client_get_bywin(globalconf.clients, ev->window)))
|
||||
{
|
||||
geometry = c->geometry;
|
||||
|
||||
if(ev->value_mask & CWX)
|
||||
if(ev->value_mask & XCB_CONFIG_WINDOW_X)
|
||||
geometry.x = ev->x;
|
||||
if(ev->value_mask & CWY)
|
||||
if(ev->value_mask & XCB_CONFIG_WINDOW_Y)
|
||||
geometry.y = ev->y;
|
||||
if(ev->value_mask & CWWidth)
|
||||
if(ev->value_mask & XCB_CONFIG_WINDOW_WIDTH)
|
||||
geometry.width = ev->width;
|
||||
if(ev->value_mask & CWHeight)
|
||||
if(ev->value_mask & XCB_CONFIG_WINDOW_HEIGHT)
|
||||
geometry.height = ev->height;
|
||||
|
||||
if(geometry.x != c->geometry.x || geometry.y != c->geometry.y
|
||||
|| geometry.width != c->geometry.width || geometry.height != c->geometry.height)
|
||||
{
|
||||
if(c->isfloating || layout_get_current(c->screen)->arrange == layout_floating)
|
||||
client_resize(c, geometry, False);
|
||||
client_resize(c, geometry, false);
|
||||
else
|
||||
{
|
||||
globalconf.screens[c->screen].need_arrange = True;
|
||||
globalconf.screens[c->screen].need_arrange = true;
|
||||
/* If we do not resize the client, at least tell it that it
|
||||
* has its new configuration. That fixes at least
|
||||
* gnome-terminal */
|
||||
|
@ -213,95 +216,108 @@ event_handle_configurerequest(XEvent * e)
|
|||
}
|
||||
else
|
||||
{
|
||||
wc.x = ev->x;
|
||||
wc.y = ev->y;
|
||||
wc.width = ev->width;
|
||||
wc.height = ev->height;
|
||||
wc.border_width = ev->border_width;
|
||||
wc.sibling = ev->above;
|
||||
wc.stack_mode = ev->detail;
|
||||
XConfigureWindow(e->xany.display, ev->window, ev->value_mask, &wc);
|
||||
const uint32_t configure_values[] = {
|
||||
ev->x, ev->y, ev->width, ev->height, ev->border_width,
|
||||
ev->sibling, ev->stack_mode };
|
||||
|
||||
xcb_configure_window(connection, ev->window, ev->value_mask,
|
||||
configure_values);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Handle XConfigure events
|
||||
* \param e XEvent
|
||||
* \param connection connection to the X server
|
||||
* \param ev ConfigureNotify event
|
||||
*/
|
||||
void
|
||||
event_handle_configurenotify(XEvent * e)
|
||||
int
|
||||
event_handle_configurenotify(void *data __attribute__ ((unused)),
|
||||
xcb_connection_t *connection, xcb_configure_notify_event_t *ev)
|
||||
{
|
||||
XConfigureEvent *ev = &e->xconfigure;
|
||||
int screen;
|
||||
int screen_nbr;
|
||||
const xcb_screen_t *screen;
|
||||
|
||||
for(screen = 0; screen < ScreenCount(e->xany.display); screen++)
|
||||
if(ev->window == RootWindow(e->xany.display, screen)
|
||||
&& (ev->width != DisplayWidth(e->xany.display, screen)
|
||||
|| ev->height != DisplayHeight(e->xany.display, screen)))
|
||||
for(screen_nbr = 0; screen_nbr < xcb_setup_roots_length (xcb_get_setup (connection)); screen_nbr++)
|
||||
if(ev->window == root_window(connection, screen_nbr)
|
||||
&& (screen = xcb_aux_get_screen(connection, screen_nbr)) != NULL
|
||||
&& (ev->width != screen->width_in_pixels
|
||||
|| ev->height != screen->height_in_pixels))
|
||||
/* it's not that we panic, but restart */
|
||||
uicb_restart(0, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Handle XDestroyWindow events
|
||||
* \param e XEvent
|
||||
* \param connection connection to the X server
|
||||
* \param ev DestroyNotify event
|
||||
*/
|
||||
void
|
||||
event_handle_destroynotify(XEvent *e)
|
||||
int
|
||||
event_handle_destroynotify(void *data __attribute__ ((unused)),
|
||||
xcb_connection_t *connection __attribute__ ((unused)),
|
||||
xcb_destroy_notify_event_t *ev)
|
||||
{
|
||||
Client *c;
|
||||
XDestroyWindowEvent *ev = &e->xdestroywindow;
|
||||
|
||||
if((c = client_get_bywin(globalconf.clients, ev->window)))
|
||||
client_unmanage(c);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Handle XCrossing events on enter
|
||||
* \param e XEvent
|
||||
/** Handle XCrossing events
|
||||
* \param connection connection to the X server
|
||||
* \param ev Crossing event
|
||||
*/
|
||||
void
|
||||
event_handle_enternotify(XEvent *e)
|
||||
int
|
||||
event_handle_enternotify(void *data __attribute__ ((unused)),
|
||||
xcb_connection_t *connection, xcb_enter_notify_event_t *ev)
|
||||
{
|
||||
Client *c;
|
||||
XCrossingEvent *ev = &e->xcrossing;
|
||||
int screen;
|
||||
|
||||
if(ev->mode != NotifyNormal
|
||||
|| (ev->x_root == globalconf.pointer_x
|
||||
&& ev->y_root == globalconf.pointer_y))
|
||||
return;
|
||||
if(ev->mode != XCB_NOTIFY_MODE_NORMAL
|
||||
|| (ev->root_x == globalconf.pointer_x
|
||||
&& ev->root_y == globalconf.pointer_y))
|
||||
return 0;
|
||||
|
||||
for(c = globalconf.clients; c; c = c->next)
|
||||
if(c->titlebar.sw && c->titlebar.sw->window == ev->window)
|
||||
if(c->titlebar.sw && c->titlebar.sw->window == ev->event)
|
||||
break;
|
||||
|
||||
if(c || (c = client_get_bywin(globalconf.clients, ev->window)))
|
||||
if(c || (c = client_get_bywin(globalconf.clients, ev->event)))
|
||||
{
|
||||
window_grabbuttons(c->win, c->phys_screen);
|
||||
/* the idea behind saving pointer_x and pointer_y is Bob Marley powered
|
||||
* this will allow us top drop some EnterNotify events and thus not giving
|
||||
* focus to windows appering under the cursor without a cursor move */
|
||||
globalconf.pointer_x = ev->x_root;
|
||||
globalconf.pointer_y = ev->y_root;
|
||||
globalconf.pointer_x = ev->root_x;
|
||||
globalconf.pointer_y = ev->root_y;
|
||||
|
||||
if(globalconf.screens[c->screen].sloppy_focus)
|
||||
client_focus(c, c->screen,
|
||||
globalconf.screens[c->screen].sloppy_focus_raise);
|
||||
}
|
||||
else
|
||||
for(screen = 0; screen < ScreenCount(e->xany.display); screen++)
|
||||
if(ev->window == RootWindow(e->xany.display, screen))
|
||||
for(screen = 0; screen < xcb_setup_roots_length(xcb_get_setup(connection)); screen++)
|
||||
if(ev->event == root_window(connection, screen))
|
||||
{
|
||||
window_root_grabbuttons(screen);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Handle XExpose events
|
||||
* \param e XEvent
|
||||
* \param ev Expose event
|
||||
*/
|
||||
void
|
||||
event_handle_expose(XEvent *e)
|
||||
int
|
||||
event_handle_expose(void *data __attribute__ ((unused)),
|
||||
xcb_connection_t *connection __attribute__ ((unused)),
|
||||
xcb_expose_event_t *ev)
|
||||
{
|
||||
XExposeEvent *ev = &e->xexpose;
|
||||
int screen;
|
||||
Statusbar *statusbar;
|
||||
Client *c;
|
||||
|
@ -313,174 +329,249 @@ event_handle_expose(XEvent *e)
|
|||
if(statusbar->sw->window == ev->window)
|
||||
{
|
||||
statusbar_display(statusbar);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(c = globalconf.clients; c; c = c->next)
|
||||
if(c->titlebar.sw && c->titlebar.sw->window == ev->window)
|
||||
{
|
||||
simplewindow_refresh_drawable(c->titlebar.sw, c->phys_screen);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Handle XKey events
|
||||
* \param e XEvent
|
||||
* \param connection connection to the X server
|
||||
* \param ev KeyPress event
|
||||
*/
|
||||
void
|
||||
event_handle_keypress(XEvent *e)
|
||||
int
|
||||
event_handle_keypress(void *data __attribute__ ((unused)),
|
||||
xcb_connection_t *connection, xcb_key_press_event_t *ev)
|
||||
{
|
||||
int screen, x, y, d;
|
||||
unsigned int m;
|
||||
XKeyEvent *ev = &e->xkey;
|
||||
KeySym keysym;
|
||||
Window dummy;
|
||||
int screen;
|
||||
xcb_query_pointer_reply_t *qpr = NULL;
|
||||
xcb_key_symbols_t *keysyms;
|
||||
xcb_keysym_t keysym;
|
||||
Key *k;
|
||||
|
||||
/* find the right screen for this event */
|
||||
for(screen = 0; screen < ScreenCount(e->xany.display); screen++)
|
||||
if(XQueryPointer(e->xany.display, RootWindow(e->xany.display, screen), &dummy, &dummy, &x, &y, &d, &d, &m))
|
||||
for(screen = 0; screen < xcb_setup_roots_length (xcb_get_setup (connection)); screen++)
|
||||
if((qpr = xcb_query_pointer_reply(connection,
|
||||
xcb_query_pointer(connection,
|
||||
root_window(connection, screen)),
|
||||
NULL)) != NULL)
|
||||
{
|
||||
/* if screen is 0, we are on first Zaphod screen or on the
|
||||
* only screen in Xinerama, so we can ask for a better screen
|
||||
* number with screen_get_bycoord: we'll get 0 in Zaphod mode
|
||||
* so it's the same, or maybe the real Xinerama screen */
|
||||
screen = screen_get_bycoord(globalconf.screens_info, screen, x, y);
|
||||
screen = screen_get_bycoord(globalconf.screens_info, screen, qpr->root_x, qpr->root_y);
|
||||
break;
|
||||
}
|
||||
|
||||
keysym = XKeycodeToKeysym(globalconf.display, (KeyCode) ev->keycode, 0);
|
||||
keysyms = xcb_key_symbols_alloc(globalconf.connection);
|
||||
keysym = xcb_key_symbols_get_keysym(keysyms, ev->detail, 0);
|
||||
|
||||
for(k = globalconf.keys; k; k = k->next)
|
||||
if(((k->keycode && ev->keycode == k->keycode) || (k->keysym && keysym == k->keysym)) &&
|
||||
k->func && CLEANMASK(k->mod) == CLEANMASK(ev->state))
|
||||
if(((k->keycode && ev->detail == k->keycode) || (k->keysym && keysym == k->keysym))
|
||||
&& k->func && CLEANMASK(k->mod) == CLEANMASK(ev->state))
|
||||
k->func(screen, k->arg);
|
||||
|
||||
xcb_key_symbols_free(keysyms);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Handle XMapping events
|
||||
* \param e XEvent
|
||||
* \param connection connection to the X server
|
||||
* \param ev MappingNotify event
|
||||
*/
|
||||
void
|
||||
event_handle_mappingnotify(XEvent *e)
|
||||
int
|
||||
event_handle_mappingnotify(void *data __attribute__ ((unused)),
|
||||
xcb_connection_t *connection, xcb_mapping_notify_event_t *ev)
|
||||
{
|
||||
XMappingEvent *ev = &e->xmapping;
|
||||
int screen;
|
||||
xcb_key_symbols_t *keysyms = xcb_key_symbols_alloc(connection);
|
||||
|
||||
XRefreshKeyboardMapping(ev);
|
||||
if(ev->request == MappingKeyboard)
|
||||
for(screen = 0; screen < ScreenCount(e->xany.display); screen++)
|
||||
xcb_refresh_keyboard_mapping(keysyms, ev);
|
||||
xcb_key_symbols_free(keysyms);
|
||||
|
||||
if(ev->request == XCB_MAPPING_KEYBOARD)
|
||||
for(screen = 0; screen < xcb_setup_roots_length(xcb_get_setup(connection)); screen++)
|
||||
window_root_grabkeys(screen);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Handle XMapRequest events
|
||||
* \param e XEvent
|
||||
* \param connection connection to the X server
|
||||
* \param ev MapRequest event
|
||||
*/
|
||||
void
|
||||
event_handle_maprequest(XEvent *e)
|
||||
int
|
||||
event_handle_maprequest(void *data __attribute__ ((unused)),
|
||||
xcb_connection_t *connection, xcb_map_request_event_t *ev)
|
||||
{
|
||||
static XWindowAttributes wa;
|
||||
XMapRequestEvent *ev = &e->xmaprequest;
|
||||
int screen = 0, x, y, d;
|
||||
unsigned int m;
|
||||
Window dummy;
|
||||
static xcb_get_window_attributes_reply_t *wa;
|
||||
int screen_nbr = 0;
|
||||
xcb_query_pointer_reply_t *qpr = NULL;
|
||||
xcb_get_geometry_reply_t *wgeom;
|
||||
xcb_screen_iterator_t iter;
|
||||
|
||||
if(!XGetWindowAttributes(e->xany.display, ev->window, &wa))
|
||||
return;
|
||||
if(wa.override_redirect)
|
||||
return;
|
||||
if((wa = xcb_get_window_attributes_reply(connection,
|
||||
xcb_get_window_attributes(connection, ev->window),
|
||||
NULL)) == NULL)
|
||||
return -1;
|
||||
if(wa->override_redirect)
|
||||
{
|
||||
p_delete(&wa);
|
||||
return 0;
|
||||
}
|
||||
if(!client_get_bywin(globalconf.clients, ev->window))
|
||||
{
|
||||
if(globalconf.screens_info->xinerama_is_active
|
||||
&& XQueryPointer(e->xany.display, RootWindow(e->xany.display, screen),
|
||||
&dummy, &dummy, &x, &y, &d, &d, &m))
|
||||
screen = screen_get_bycoord(globalconf.screens_info, screen, x, y);
|
||||
else
|
||||
for(screen = 0; wa.screen != ScreenOfDisplay(e->xany.display, screen); screen++);
|
||||
if((wgeom = xcb_get_geometry_reply(connection,
|
||||
xcb_get_geometry(connection, ev->window), NULL)) == NULL)
|
||||
return -1;
|
||||
|
||||
client_manage(ev->window, &wa, screen);
|
||||
if(globalconf.screens_info->xinerama_is_active
|
||||
&& (qpr = xcb_query_pointer_reply(connection,
|
||||
xcb_query_pointer(connection,
|
||||
root_window(globalconf.connection, screen_nbr)),
|
||||
NULL)) != NULL)
|
||||
screen_nbr = screen_get_bycoord(globalconf.screens_info, screen_nbr, qpr->root_x, qpr->root_y);
|
||||
else
|
||||
for (iter = xcb_setup_roots_iterator (xcb_get_setup (connection)), screen_nbr = 0;
|
||||
iter.rem && iter.data->root != wgeom->root; xcb_screen_next (&iter), ++screen_nbr);
|
||||
|
||||
if(qpr)
|
||||
p_delete(&qpr);
|
||||
|
||||
client_manage(ev->window, wgeom, screen_nbr);
|
||||
p_delete(&wgeom);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Handle XProperty events
|
||||
* \param e XEvent
|
||||
* \param connection connection to the X server
|
||||
* \param ev PropertyNotify event
|
||||
*/
|
||||
void
|
||||
event_handle_propertynotify(XEvent * e)
|
||||
int
|
||||
event_handle_propertynotify(void *data __attribute__ ((unused)),
|
||||
xcb_connection_t *connection, xcb_property_notify_event_t *ev)
|
||||
{
|
||||
Client *c;
|
||||
Window trans;
|
||||
XPropertyEvent *ev = &e->xproperty;
|
||||
xcb_window_t trans;
|
||||
|
||||
if(ev->state == PropertyDelete)
|
||||
return; /* ignore */
|
||||
if(ev->state == XCB_PROPERTY_DELETE)
|
||||
return 0; /* ignore */
|
||||
if((c = client_get_bywin(globalconf.clients, ev->window)))
|
||||
{
|
||||
switch (ev->atom)
|
||||
if(ev->atom == WM_TRANSIENT_FOR)
|
||||
{
|
||||
case XA_WM_TRANSIENT_FOR:
|
||||
XGetTransientForHint(e->xany.display, c->win, &trans);
|
||||
x_get_transient_for_hint(connection, c->win, &trans);
|
||||
if(!c->isfloating
|
||||
&& (c->isfloating = (client_get_bywin(globalconf.clients, trans) != NULL)))
|
||||
globalconf.screens[c->screen].need_arrange = True;
|
||||
break;
|
||||
case XA_WM_NORMAL_HINTS:
|
||||
client_updatesizehints(c);
|
||||
break;
|
||||
case XA_WM_HINTS:
|
||||
client_updatewmhints(c);
|
||||
break;
|
||||
globalconf.screens[c->screen].need_arrange = true;
|
||||
}
|
||||
if(ev->atom == XA_WM_NAME || ev->atom == XInternAtom(globalconf.display, "_NET_WM_NAME", False))
|
||||
else if (ev->atom == WM_NORMAL_HINTS)
|
||||
client_updatesizehints(c);
|
||||
else if (ev->atom == WM_HINTS)
|
||||
client_updatewmhints(c);
|
||||
|
||||
if(ev->atom == WM_NAME || ev->atom == x_intern_atom(globalconf.connection, "_NET_WM_NAME"))
|
||||
client_updatetitle(c);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Handle XUnmap events
|
||||
* \param e XEvent
|
||||
* \param connection connection to the X server
|
||||
* \param ev UnmapNotify event
|
||||
*/
|
||||
void
|
||||
event_handle_unmapnotify(XEvent * e)
|
||||
int
|
||||
event_handle_unmapnotify(void *data __attribute__ ((unused)),
|
||||
xcb_connection_t *connection, xcb_unmap_notify_event_t *ev)
|
||||
{
|
||||
Client *c;
|
||||
XUnmapEvent *ev = &e->xunmap;
|
||||
|
||||
/*
|
||||
* event->send_event (Xlib) is quivalent to (ev->response_type &
|
||||
* 0x80) in XCB because the SendEvent bit is available in the
|
||||
* response_type field
|
||||
*/
|
||||
bool send_event = ((ev->response_type & 0x80) >> 7);
|
||||
|
||||
if((c = client_get_bywin(globalconf.clients, ev->window))
|
||||
&& ev->event == RootWindow(e->xany.display, c->phys_screen)
|
||||
&& ev->send_event && window_getstate(c->win) == NormalState)
|
||||
&& ev->event == root_window(connection, c->phys_screen)
|
||||
&& send_event && window_getstate(c->win) == XCB_WM_NORMAL_STATE)
|
||||
client_unmanage(c);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Handle XShape events
|
||||
* \param e XEvent
|
||||
* \param ev Shape event
|
||||
*/
|
||||
void
|
||||
event_handle_shape(XEvent * e)
|
||||
int
|
||||
event_handle_shape(void *data __attribute__ ((unused)),
|
||||
xcb_connection_t *connection __attribute__ ((unused)),
|
||||
xcb_shape_notify_event_t *ev)
|
||||
{
|
||||
XShapeEvent *ev = (XShapeEvent *) e;
|
||||
Client *c = client_get_bywin(globalconf.clients, ev->window);
|
||||
Client *c = client_get_bywin(globalconf.clients, ev->affected_window);
|
||||
|
||||
if(c)
|
||||
window_setshape(c->win, c->phys_screen);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Handle XRandR events
|
||||
* \param e XEvent
|
||||
* \param ev RandrScreenChangeNotify event
|
||||
*/
|
||||
void
|
||||
event_handle_randr_screen_change_notify(XEvent *e)
|
||||
int
|
||||
event_handle_randr_screen_change_notify(void *data __attribute__ ((unused)),
|
||||
xcb_connection_t *connection __attribute__ ((unused)),
|
||||
xcb_randr_screen_change_notify_event_t *ev)
|
||||
{
|
||||
XRRUpdateConfiguration(e);
|
||||
if(!globalconf.have_randr)
|
||||
return -1;
|
||||
|
||||
/* Code of XRRUpdateConfiguration Xlib function ported to XCB
|
||||
* (only the code relevant to RRScreenChangeNotify) as the latter
|
||||
* doesn't provide this kind of function */
|
||||
if(ev->rotation & (XCB_RANDR_ROTATION_ROTATE_90 | XCB_RANDR_ROTATION_ROTATE_270))
|
||||
xcb_randr_set_screen_size(connection, ev->root, ev->height, ev->width,
|
||||
ev->mheight, ev->mwidth);
|
||||
else
|
||||
xcb_randr_set_screen_size(connection, ev->root, ev->width, ev->height,
|
||||
ev->mwidth, ev->mheight);
|
||||
|
||||
/* TODO:
|
||||
* XRRUpdateConfiguration also executes the following instruction
|
||||
* but I don't know yet how to port it to XCB
|
||||
*
|
||||
* XRenderSetSubpixelOrder(dpy, snum, scevent->subpixel_order);
|
||||
*/
|
||||
|
||||
uicb_restart(0, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Handle XClientMessage events
|
||||
* \param e XEvent
|
||||
* \param ev ClientMessage event
|
||||
*/
|
||||
void
|
||||
event_handle_clientmessage(XEvent *e)
|
||||
int
|
||||
event_handle_clientmessage(void *data __attribute__ ((unused)),
|
||||
xcb_connection_t *connection __attribute__ ((unused)),
|
||||
xcb_client_message_event_t *ev)
|
||||
{
|
||||
ewmh_process_client_message(&e->xclient);
|
||||
ewmh_process_client_message(ev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||
|
|
34
event.h
34
event.h
|
@ -22,24 +22,26 @@
|
|||
#ifndef AWESOME_EVENT_H
|
||||
#define AWESOME_EVENT_H
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/randr.h>
|
||||
#include <xcb/shape.h>
|
||||
|
||||
#define CLEANMASK(mask) (mask & ~(globalconf.numlockmask | LockMask))
|
||||
#define CLEANMASK(mask) (mask & ~(globalconf.numlockmask | XCB_MOD_MASK_LOCK))
|
||||
|
||||
void event_handle_buttonpress(XEvent *);
|
||||
void event_handle_configurerequest(XEvent *);
|
||||
void event_handle_configurenotify(XEvent *);
|
||||
void event_handle_destroynotify(XEvent *);
|
||||
void event_handle_enternotify(XEvent *);
|
||||
void event_handle_expose(XEvent *);
|
||||
void event_handle_keypress(XEvent *);
|
||||
void event_handle_mappingnotify(XEvent *);
|
||||
void event_handle_maprequest(XEvent *);
|
||||
void event_handle_propertynotify(XEvent *);
|
||||
void event_handle_unmapnotify(XEvent *);
|
||||
void event_handle_shape(XEvent *);
|
||||
void event_handle_randr_screen_change_notify(XEvent *);
|
||||
void event_handle_clientmessage(XEvent *);
|
||||
int event_handle_buttonpress(void *, xcb_connection_t *, xcb_button_press_event_t *);
|
||||
int event_handle_configurerequest(void *, xcb_connection_t *, xcb_configure_request_event_t *);
|
||||
int event_handle_configurenotify(void *, xcb_connection_t *, xcb_configure_notify_event_t *);
|
||||
int event_handle_destroynotify(void *, xcb_connection_t *, xcb_destroy_notify_event_t *);
|
||||
int event_handle_enternotify(void *, xcb_connection_t *, xcb_enter_notify_event_t *);
|
||||
int event_handle_expose(void *, xcb_connection_t *, xcb_expose_event_t *);
|
||||
int event_handle_keypress(void *, xcb_connection_t *, xcb_key_press_event_t *);
|
||||
int event_handle_mappingnotify(void *, xcb_connection_t *, xcb_mapping_notify_event_t *);
|
||||
int event_handle_maprequest(void *, xcb_connection_t *, xcb_map_request_event_t *);
|
||||
int event_handle_propertynotify(void *, xcb_connection_t *, xcb_property_notify_event_t *);
|
||||
int event_handle_unmapnotify(void *, xcb_connection_t *, xcb_unmap_notify_event_t *);
|
||||
int event_handle_shape(void *, xcb_connection_t *, xcb_shape_notify_event_t *);
|
||||
int event_handle_randr_screen_change_notify(void *, xcb_connection_t *, xcb_randr_screen_change_notify_event_t *);
|
||||
int event_handle_clientmessage(void *, xcb_connection_t *, xcb_client_message_event_t *);
|
||||
|
||||
#endif
|
||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||
|
|
264
ewmh.c
264
ewmh.c
|
@ -19,8 +19,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xmd.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_atom.h>
|
||||
|
||||
#include "ewmh.h"
|
||||
#include "tag.h"
|
||||
|
@ -32,36 +32,34 @@
|
|||
|
||||
extern AwesomeConf globalconf;
|
||||
|
||||
static Atom net_supported;
|
||||
static Atom net_client_list;
|
||||
static Atom net_number_of_desktops;
|
||||
static Atom net_current_desktop;
|
||||
static Atom net_desktop_names;
|
||||
static Atom net_active_window;
|
||||
static xcb_atom_t net_supported;
|
||||
static xcb_atom_t net_client_list;
|
||||
static xcb_atom_t net_number_of_desktops;
|
||||
static xcb_atom_t net_current_desktop;
|
||||
static xcb_atom_t net_desktop_names;
|
||||
static xcb_atom_t net_active_window;
|
||||
static xcb_atom_t net_close_window;
|
||||
static xcb_atom_t net_wm_name;
|
||||
static xcb_atom_t net_wm_icon_name;
|
||||
static xcb_atom_t net_wm_window_type;
|
||||
static xcb_atom_t net_wm_window_type_normal;
|
||||
static xcb_atom_t net_wm_window_type_dock;
|
||||
static xcb_atom_t net_wm_window_type_splash;
|
||||
static xcb_atom_t net_wm_window_type_dialog;
|
||||
static xcb_atom_t net_wm_icon;
|
||||
static xcb_atom_t net_wm_state;
|
||||
static xcb_atom_t net_wm_state_sticky;
|
||||
static xcb_atom_t net_wm_state_skip_taskbar;
|
||||
static xcb_atom_t net_wm_state_fullscreen;
|
||||
static xcb_atom_t net_wm_state_above;
|
||||
static xcb_atom_t net_wm_state_below;
|
||||
|
||||
static Atom net_close_window;
|
||||
|
||||
static Atom net_wm_name;
|
||||
static Atom net_wm_icon_name;
|
||||
static Atom net_wm_window_type;
|
||||
static Atom net_wm_window_type_normal;
|
||||
static Atom net_wm_window_type_dock;
|
||||
static Atom net_wm_window_type_splash;
|
||||
static Atom net_wm_window_type_dialog;
|
||||
static Atom net_wm_icon;
|
||||
static Atom net_wm_state;
|
||||
static Atom net_wm_state_sticky;
|
||||
static Atom net_wm_state_skip_taskbar;
|
||||
static Atom net_wm_state_fullscreen;
|
||||
static Atom net_wm_state_above;
|
||||
static Atom net_wm_state_below;
|
||||
|
||||
static Atom utf8_string;
|
||||
static xcb_atom_t utf8_string;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const char *name;
|
||||
Atom *atom;
|
||||
xcb_atom_t *atom;
|
||||
} AtomItem;
|
||||
|
||||
static AtomItem AtomNames[] =
|
||||
|
@ -103,20 +101,35 @@ void
|
|||
ewmh_init_atoms(void)
|
||||
{
|
||||
unsigned int i;
|
||||
char *names[ATOM_NUMBER];
|
||||
Atom atoms[ATOM_NUMBER];
|
||||
xcb_intern_atom_cookie_t cs[ATOM_NUMBER];
|
||||
xcb_intern_atom_reply_t *r;
|
||||
|
||||
/*
|
||||
* Create the atom and get the reply in a XCB way (e.g. send all
|
||||
* the requests at the same time and then get the replies)
|
||||
*/
|
||||
for(i = 0; i < ATOM_NUMBER; i++)
|
||||
cs[i] = xcb_intern_atom_unchecked(globalconf.connection,
|
||||
false,
|
||||
strlen(AtomNames[i].name),
|
||||
AtomNames[i].name);
|
||||
|
||||
for(i = 0; i < ATOM_NUMBER; i++)
|
||||
names[i] = (char *) AtomNames[i].name;
|
||||
XInternAtoms(globalconf.display, names, ATOM_NUMBER, False, atoms);
|
||||
for(i = 0; i < ATOM_NUMBER; i++)
|
||||
*AtomNames[i].atom = atoms[i];
|
||||
{
|
||||
r = xcb_intern_atom_reply(globalconf.connection, cs[i], NULL);
|
||||
if(!r)
|
||||
/* An error occured, get reply for next atom */
|
||||
continue;
|
||||
|
||||
*AtomNames[i].atom = r->atom;
|
||||
p_delete(&r);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ewmh_set_supported_hints(int phys_screen)
|
||||
{
|
||||
Atom atom[ATOM_NUMBER];
|
||||
xcb_atom_t atom[ATOM_NUMBER];
|
||||
int i = 0;
|
||||
|
||||
atom[i++] = net_supported;
|
||||
|
@ -143,29 +156,30 @@ ewmh_set_supported_hints(int phys_screen)
|
|||
atom[i++] = net_wm_state_above;
|
||||
atom[i++] = net_wm_state_below;
|
||||
|
||||
XChangeProperty(globalconf.display, RootWindow(globalconf.display, phys_screen),
|
||||
net_supported, XA_ATOM, 32,
|
||||
PropModeReplace, (unsigned char *) atom, i);
|
||||
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
|
||||
root_window(globalconf.connection, phys_screen),
|
||||
net_supported, ATOM, 32, i, atom);
|
||||
}
|
||||
|
||||
void
|
||||
ewmh_update_net_client_list(int phys_screen)
|
||||
{
|
||||
Window *wins;
|
||||
xcb_window_t *wins;
|
||||
Client *c;
|
||||
int n = 0;
|
||||
|
||||
for(c = globalconf.clients; c; c = c->next)
|
||||
n++;
|
||||
|
||||
wins = p_new(Window, n);
|
||||
wins = p_new(xcb_window_t, n);
|
||||
|
||||
for(n = 0, c = globalconf.clients; c; c = c->next, n++)
|
||||
if(c->phys_screen == phys_screen)
|
||||
wins[n] = c->win;
|
||||
|
||||
XChangeProperty(globalconf.display, RootWindow(globalconf.display, phys_screen),
|
||||
net_client_list, XA_WINDOW, 32, PropModeReplace, (unsigned char *) wins, n);
|
||||
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
|
||||
root_window(globalconf.connection, phys_screen),
|
||||
net_client_list, WINDOW, 32, n, wins);
|
||||
|
||||
p_delete(&wins);
|
||||
}
|
||||
|
@ -173,27 +187,29 @@ ewmh_update_net_client_list(int phys_screen)
|
|||
void
|
||||
ewmh_update_net_numbers_of_desktop(int phys_screen)
|
||||
{
|
||||
CARD32 count = 0;
|
||||
uint32_t count = 0;
|
||||
Tag *tag;
|
||||
|
||||
for(tag = globalconf.screens[phys_screen].tags; tag; tag = tag->next)
|
||||
count++;
|
||||
|
||||
XChangeProperty(globalconf.display, RootWindow(globalconf.display, phys_screen),
|
||||
net_number_of_desktops, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &count, 1);
|
||||
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
|
||||
root_window(globalconf.connection, phys_screen),
|
||||
net_number_of_desktops, CARDINAL, 32, 1, &count);
|
||||
}
|
||||
|
||||
void
|
||||
ewmh_update_net_current_desktop(int phys_screen)
|
||||
{
|
||||
CARD32 count = 0;
|
||||
uint32_t count = 0;
|
||||
Tag *tag, **curtags = tags_get_current(phys_screen);
|
||||
|
||||
for(tag = globalconf.screens[phys_screen].tags; tag != curtags[0]; tag = tag->next)
|
||||
count++;
|
||||
|
||||
XChangeProperty(globalconf.display, RootWindow(globalconf.display, phys_screen),
|
||||
net_current_desktop, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &count, 1);
|
||||
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
|
||||
root_window(globalconf.connection, phys_screen),
|
||||
net_current_desktop, CARDINAL, 32, 1, &count);
|
||||
|
||||
p_delete(&curtags);
|
||||
}
|
||||
|
@ -215,25 +231,29 @@ ewmh_update_net_desktop_names(int phys_screen)
|
|||
len += curr_size + 1;
|
||||
}
|
||||
|
||||
XChangeProperty(globalconf.display, RootWindow(globalconf.display, phys_screen),
|
||||
net_desktop_names, utf8_string, 8, PropModeReplace, (unsigned char *) buf, len);
|
||||
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
|
||||
root_window(globalconf.connection, phys_screen),
|
||||
net_desktop_names, utf8_string, 8, len, buf);
|
||||
}
|
||||
|
||||
void
|
||||
ewmh_update_net_active_window(int phys_screen)
|
||||
{
|
||||
Window win;
|
||||
xcb_window_t win;
|
||||
Client *sel = focus_get_current_client(phys_screen);
|
||||
|
||||
win = sel ? sel->win : None;
|
||||
win = sel ? sel->win : XCB_NONE;
|
||||
|
||||
XChangeProperty(globalconf.display, RootWindow(globalconf.display, phys_screen),
|
||||
net_active_window, XA_WINDOW, 32, PropModeReplace, (unsigned char *) &win, 1);
|
||||
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
|
||||
root_window(globalconf.connection, phys_screen),
|
||||
net_active_window, WINDOW, 32, 1, &win);
|
||||
}
|
||||
|
||||
static void
|
||||
ewmh_process_state_atom(Client *c, Atom state, int set)
|
||||
ewmh_process_state_atom(Client *c, xcb_atom_t state, int set)
|
||||
{
|
||||
const uint32_t raise_window_val = XCB_STACK_MODE_ABOVE;
|
||||
|
||||
if(state == net_wm_state_sticky)
|
||||
{
|
||||
Tag *tag;
|
||||
|
@ -244,13 +264,13 @@ ewmh_process_state_atom(Client *c, Atom state, int set)
|
|||
{
|
||||
if(set == _NET_WM_STATE_REMOVE)
|
||||
{
|
||||
c->skiptb = False;
|
||||
c->skip = False;
|
||||
c->skiptb = false;
|
||||
c->skip = false;
|
||||
}
|
||||
else if(set == _NET_WM_STATE_ADD)
|
||||
{
|
||||
c->skiptb = True;
|
||||
c->skip = True;
|
||||
c->skiptb = true;
|
||||
c->skip = true;
|
||||
}
|
||||
}
|
||||
else if(state == net_wm_state_fullscreen)
|
||||
|
@ -263,7 +283,7 @@ ewmh_process_state_atom(Client *c, Atom state, int set)
|
|||
/* restore borders and titlebar */
|
||||
titlebar_position_set(&c->titlebar, c->titlebar.dposition);
|
||||
c->border = c->oldborder;
|
||||
c->ismax = False;
|
||||
c->ismax = false;
|
||||
client_setfloating(c, c->wasfloating, c->oldlayer);
|
||||
}
|
||||
else if(set == _NET_WM_STATE_ADD)
|
||||
|
@ -276,12 +296,12 @@ ewmh_process_state_atom(Client *c, Atom state, int set)
|
|||
titlebar_position_set(&c->titlebar, Off);
|
||||
c->oldborder = c->border;
|
||||
c->border = 0;
|
||||
c->ismax = True;
|
||||
client_setfloating(c, True, LAYER_FULLSCREEN);
|
||||
c->ismax = true;
|
||||
client_setfloating(c, true, LAYER_FULLSCREEN);
|
||||
}
|
||||
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
||||
client_resize(c, geometry, False);
|
||||
XRaiseWindow(globalconf.display, c->win);
|
||||
client_resize(c, geometry, false);
|
||||
xcb_configure_window(globalconf.connection, c->win, XCB_CONFIG_WINDOW_STACK_MODE, &raise_window_val);
|
||||
}
|
||||
else if(state == net_wm_state_above)
|
||||
{
|
||||
|
@ -311,7 +331,7 @@ ewmh_process_state_atom(Client *c, Atom state, int set)
|
|||
}
|
||||
|
||||
static void
|
||||
ewmh_process_window_type_atom(Client *c, Atom state)
|
||||
ewmh_process_window_type_atom(Client *c, xcb_atom_t state)
|
||||
{
|
||||
if(state == net_wm_window_type_normal)
|
||||
{
|
||||
|
@ -321,40 +341,47 @@ ewmh_process_window_type_atom(Client *c, Atom state)
|
|||
|| state == net_wm_window_type_splash)
|
||||
{
|
||||
c->border = 0;
|
||||
c->skip = True;
|
||||
c->isfixed = True;
|
||||
c->skip = true;
|
||||
c->isfixed = true;
|
||||
titlebar_position_set(&c->titlebar, Off);
|
||||
client_setfloating(c, True, LAYER_ABOVE);
|
||||
client_setfloating(c, true, LAYER_ABOVE);
|
||||
}
|
||||
else if (state == net_wm_window_type_dialog)
|
||||
{
|
||||
client_setfloating(c, True, LAYER_ABOVE);
|
||||
}
|
||||
client_setfloating(c, true, LAYER_ABOVE);
|
||||
}
|
||||
|
||||
void
|
||||
ewmh_process_client_message(XClientMessageEvent *ev)
|
||||
ewmh_process_client_message(xcb_client_message_event_t *ev)
|
||||
{
|
||||
Client *c;
|
||||
int screen;
|
||||
|
||||
if(ev->message_type == net_current_desktop)
|
||||
for(screen = 0; screen < ScreenCount(globalconf.display); screen++)
|
||||
if(ev->window == RootWindow(globalconf.display, screen))
|
||||
tag_view_only_byindex(screen, ev->data.l[0]);
|
||||
/* TODO: check whether it's correct to use 'type' this way */
|
||||
if(ev->type == net_current_desktop)
|
||||
for(screen = 0;
|
||||
screen < xcb_setup_roots_length(xcb_get_setup(globalconf.connection));
|
||||
screen++)
|
||||
{
|
||||
if(ev->window == root_window(globalconf.connection, screen))
|
||||
tag_view_only_byindex(screen, ev->data.data32[0]);
|
||||
}
|
||||
|
||||
if(ev->message_type == net_close_window)
|
||||
if(ev->type == net_close_window)
|
||||
{
|
||||
if((c = client_get_bywin(globalconf.clients, ev->window)))
|
||||
client_kill(c);
|
||||
}
|
||||
else if(ev->message_type == net_wm_state)
|
||||
else if(ev->type == net_wm_state)
|
||||
{
|
||||
if((c = client_get_bywin(globalconf.clients, ev->window)))
|
||||
{
|
||||
ewmh_process_state_atom(c, (Atom) ev->data.l[1], ev->data.l[0]);
|
||||
if(ev->data.l[2])
|
||||
ewmh_process_state_atom(c, (Atom) ev->data.l[2], ev->data.l[0]);
|
||||
ewmh_process_state_atom(c, (xcb_atom_t) ev->data.data32[1], ev->data.data32[0]);
|
||||
/* TODO: is data32[2] really useful because it doesn't
|
||||
* seem to be used when sending a ClientMessage in
|
||||
* event.c:897 */
|
||||
if(ev->data.data32[2])
|
||||
ewmh_process_state_atom(c, (xcb_atom_t) ev->data.data32[2],
|
||||
ev->data.data32[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -362,53 +389,66 @@ ewmh_process_client_message(XClientMessageEvent *ev)
|
|||
void
|
||||
ewmh_check_client_hints(Client *c)
|
||||
{
|
||||
int format;
|
||||
Atom real, *state;
|
||||
unsigned char *data = NULL;
|
||||
unsigned long i, n, extra;
|
||||
xcb_atom_t *state;
|
||||
void *data = NULL;
|
||||
int i;
|
||||
|
||||
if(XGetWindowProperty(globalconf.display, c->win, net_wm_state, 0L, LONG_MAX, False,
|
||||
XA_ATOM, &real, &format, &n, &extra,
|
||||
(unsigned char **) &data) == Success && data)
|
||||
xcb_get_property_cookie_t c1, c2;
|
||||
xcb_get_property_reply_t *reply;
|
||||
|
||||
/* Send the GetProperty requests which will be processed later */
|
||||
c1 = xcb_get_property_unchecked(globalconf.connection, false, c->win,
|
||||
net_wm_state, ATOM, 0, UINT32_MAX);
|
||||
|
||||
c2 = xcb_get_property_unchecked(globalconf.connection, false, c->win,
|
||||
net_wm_window_type, ATOM, 0, UINT32_MAX);
|
||||
|
||||
reply = xcb_get_property_reply(globalconf.connection, c1, NULL);
|
||||
if(reply && (data = xcb_get_property_value(reply)))
|
||||
{
|
||||
state = (Atom *) data;
|
||||
for(i = 0; i < n; i++)
|
||||
state = (xcb_atom_t *) data;
|
||||
for(i = 0; i < xcb_get_property_value_length(reply); i++)
|
||||
ewmh_process_state_atom(c, state[i], _NET_WM_STATE_ADD);
|
||||
|
||||
XFree(data);
|
||||
}
|
||||
|
||||
if(XGetWindowProperty(globalconf.display, c->win, net_wm_window_type, 0L, LONG_MAX, False,
|
||||
XA_ATOM, &real, &format, &n, &extra,
|
||||
(unsigned char **) &data) == Success && data)
|
||||
p_delete(&reply);
|
||||
|
||||
reply = xcb_get_property_reply(globalconf.connection, c2, NULL);
|
||||
if(reply && (data = xcb_get_property_value(reply)))
|
||||
{
|
||||
state = (Atom *) data;
|
||||
for(i = 0; i < n; i++)
|
||||
state = (xcb_atom_t *) data;
|
||||
for(i = 0; i < xcb_get_property_value_length(reply); i++)
|
||||
ewmh_process_window_type_atom(c, state[i]);
|
||||
|
||||
XFree(data);
|
||||
}
|
||||
|
||||
p_delete(&reply);
|
||||
}
|
||||
|
||||
NetWMIcon *
|
||||
ewmh_get_window_icon(Window w)
|
||||
ewmh_get_window_icon(xcb_window_t w)
|
||||
{
|
||||
double alpha;
|
||||
NetWMIcon *icon;
|
||||
Atom type;
|
||||
int format, size, i;
|
||||
unsigned long items, rest, *data;
|
||||
int size, i;
|
||||
unsigned long *data;
|
||||
unsigned char *imgdata, *wdata;
|
||||
xcb_get_property_reply_t *r;
|
||||
|
||||
if(XGetWindowProperty(globalconf.display, w,
|
||||
net_wm_icon, 0L, LONG_MAX, False, XA_CARDINAL, &type, &format,
|
||||
&items, &rest, &wdata) != Success
|
||||
|| !wdata)
|
||||
return NULL;
|
||||
|
||||
if(type != XA_CARDINAL || format != 32 || items < 2)
|
||||
r = xcb_get_property_reply(globalconf.connection,
|
||||
xcb_get_property_unchecked(globalconf.connection, false, w,
|
||||
net_wm_icon, CARDINAL, 0, UINT32_MAX),
|
||||
NULL);
|
||||
if(!r || !(wdata = (unsigned char *) xcb_get_property_value(r)))
|
||||
{
|
||||
XFree(wdata);
|
||||
if(r)
|
||||
p_delete(&r);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(r->type != CARDINAL || r->format != 32 || r->length < 2)
|
||||
{
|
||||
p_delete(&r);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -423,7 +463,7 @@ ewmh_get_window_icon(Window w)
|
|||
if(!size)
|
||||
{
|
||||
p_delete(&icon);
|
||||
XFree(wdata);
|
||||
p_delete(&r);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -437,7 +477,7 @@ ewmh_get_window_icon(Window w)
|
|||
imgdata[0] = (data[i] & 0xff) * alpha; /* B */
|
||||
}
|
||||
|
||||
XFree(wdata);
|
||||
p_delete(&r);
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
|
4
ewmh.h
4
ewmh.h
|
@ -38,9 +38,9 @@ void ewmh_update_net_numbers_of_desktop(int);
|
|||
void ewmh_update_net_current_desktop(int);
|
||||
void ewmh_update_net_desktop_names(int);
|
||||
void ewmh_update_net_active_window(int);
|
||||
void ewmh_process_client_message(XClientMessageEvent *);
|
||||
void ewmh_process_client_message(xcb_client_message_event_t *);
|
||||
void ewmh_check_client_hints(Client *);
|
||||
NetWMIcon * ewmh_get_window_icon(Window);
|
||||
NetWMIcon * ewmh_get_window_icon(xcb_window_t);
|
||||
|
||||
#endif
|
||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||
|
|
4
focus.c
4
focus.c
|
@ -122,7 +122,7 @@ uicb_focus_history(int screen, char *arg)
|
|||
c = focus_get_latest_client_for_tags(curtags, i);
|
||||
p_delete(&curtags);
|
||||
if(c)
|
||||
client_focus(c, screen, True);
|
||||
client_focus(c, screen, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ uicb_focus_client_byname(int screen, char *arg)
|
|||
if((c = client_get_byname(globalconf.clients, arg)))
|
||||
for(tag = curtags; *tag; tag++)
|
||||
if(is_client_tagged(c, *tag))
|
||||
client_focus(c, screen, True);
|
||||
client_focus(c, screen, true);
|
||||
p_delete(&curtags);
|
||||
}
|
||||
}
|
||||
|
|
32
layout.c
32
layout.c
|
@ -19,8 +19,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_atom.h>
|
||||
|
||||
#include "tag.h"
|
||||
#include "focus.h"
|
||||
|
@ -45,9 +45,8 @@ arrange(int screen)
|
|||
{
|
||||
Client *c;
|
||||
Layout *curlay = layout_get_current(screen);
|
||||
unsigned int dui;
|
||||
int di, x, y, phys_screen = screen_virttophys(screen);
|
||||
Window rootwin, childwin;
|
||||
int phys_screen = screen_virttophys(screen);
|
||||
xcb_query_pointer_reply_t *xqp;
|
||||
|
||||
for(c = globalconf.clients; c; c = c->next)
|
||||
{
|
||||
|
@ -63,12 +62,12 @@ arrange(int screen)
|
|||
for(c = globalconf.clients; c; c = c->next)
|
||||
if(c->newcomer && client_isvisible(c, screen))
|
||||
{
|
||||
c->newcomer = False;
|
||||
c->newcomer = false;
|
||||
client_unban(c);
|
||||
if(globalconf.screens[screen].new_get_focus
|
||||
&& !c->skip
|
||||
&& (!globalconf.focus->client || !globalconf.focus->client->ismax))
|
||||
client_focus(c, screen, True);
|
||||
client_focus(c, screen, true);
|
||||
else if(globalconf.focus->client && globalconf.focus->client->ismax)
|
||||
client_stack(globalconf.focus->client);
|
||||
}
|
||||
|
@ -76,22 +75,23 @@ arrange(int screen)
|
|||
/* if we have a valid client that could be focused but currently no window
|
||||
* are focused, then set the focus on this window */
|
||||
if((c = focus_get_current_client(screen)) && globalconf.focus->client != c)
|
||||
client_focus(c, screen, True);
|
||||
client_focus(c, screen, true);
|
||||
|
||||
/* check that the mouse is on a window or not */
|
||||
if(XQueryPointer(globalconf.display,
|
||||
RootWindow(globalconf.display, phys_screen),
|
||||
&rootwin, &childwin, &x, &y, &di, &di, &dui))
|
||||
if((xqp = xcb_query_pointer_reply(globalconf.connection,
|
||||
xcb_query_pointer_unchecked(globalconf.connection,
|
||||
root_window(globalconf.connection,
|
||||
phys_screen)),
|
||||
NULL)) != NULL
|
||||
&& (xqp->root == XCB_NONE || xqp->child == XCB_NONE || xqp->root == xqp->child))
|
||||
{
|
||||
if(rootwin == None || childwin == None || childwin == rootwin)
|
||||
window_root_grabbuttons(phys_screen);
|
||||
|
||||
globalconf.pointer_x = x;
|
||||
globalconf.pointer_y = y;
|
||||
globalconf.pointer_x = xqp->root_x;
|
||||
globalconf.pointer_y = xqp->root_y;
|
||||
}
|
||||
|
||||
/* reset status */
|
||||
globalconf.screens[screen].need_arrange = False;
|
||||
globalconf.screens[screen].need_arrange = false;
|
||||
}
|
||||
|
||||
/** Refresh the screen disposition
|
||||
|
|
2
layout.h
2
layout.h
|
@ -22,8 +22,6 @@
|
|||
#ifndef AWESOME_LAYOUT_H
|
||||
#define AWESOME_LAYOUT_H
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
#include "uicb.h"
|
||||
#include "common/list.h"
|
||||
#include "common/util.h"
|
||||
|
|
|
@ -43,7 +43,7 @@ layout_fibonacci(int screen, int shape)
|
|||
for(c = globalconf.clients; c; c = c->next)
|
||||
if(IS_TILED(c, screen))
|
||||
{
|
||||
c->ismax = False;
|
||||
c->ismax = false;
|
||||
if((i % 2 && geometry.height / 2 > 2 * c->border)
|
||||
|| (!(i % 2) && geometry.width / 2 > 2 * c->border))
|
||||
{
|
||||
|
|
|
@ -32,6 +32,6 @@ layout_floating(int screen)
|
|||
|
||||
for(c = globalconf.clients; c; c = c->next)
|
||||
if(client_isvisible(c, screen) && !c->ismax)
|
||||
client_resize(c, c->f_geometry, False);
|
||||
client_resize(c, c->f_geometry, false);
|
||||
}
|
||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||
|
|
|
@ -40,7 +40,7 @@ layout_max(int screen)
|
|||
{
|
||||
area.width -= 2 * c->border;
|
||||
area.height -= 2 * c->border;
|
||||
client_resize(c, area, False);
|
||||
client_resize(c, area, false);
|
||||
area.width += 2 * c->border;
|
||||
area.height += 2 * c->border;
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ uicb_tag_setnmaster(int screen, char * arg)
|
|||
|
||||
p_delete(&curtags);
|
||||
|
||||
globalconf.screens[screen].need_arrange = True;
|
||||
globalconf.screens[screen].need_arrange = true;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -87,7 +87,7 @@ uicb_tag_setncol(int screen, char * arg)
|
|||
|
||||
p_delete(&curtags);
|
||||
|
||||
globalconf.screens[screen].need_arrange = True;
|
||||
globalconf.screens[screen].need_arrange = true;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -121,7 +121,7 @@ uicb_tag_setmwfact(int screen, char *arg)
|
|||
|
||||
p_delete(&newarg);
|
||||
p_delete(&curtags);
|
||||
globalconf.screens[screen].need_arrange = True;
|
||||
globalconf.screens[screen].need_arrange = true;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
235
mouse.c
235
mouse.c
|
@ -31,7 +31,7 @@
|
|||
#include "layouts/tile.h"
|
||||
#include "common/xscreen.h"
|
||||
|
||||
#define MOUSEMASK (ButtonPressMask | ButtonReleaseMask | PointerMotionMask)
|
||||
#define MOUSEMASK (XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION)
|
||||
|
||||
extern AwesomeConf globalconf;
|
||||
|
||||
|
@ -133,117 +133,143 @@ mouse_resizebar_draw(DrawCtx *ctx, style_t style, SimpleWindow *sw, area_t geome
|
|||
void
|
||||
uicb_client_movemouse(int screen, char *arg __attribute__ ((unused)))
|
||||
{
|
||||
int x, y, ocx, ocy, di, newscreen;
|
||||
unsigned int dui;
|
||||
Window dummy, child;
|
||||
XEvent ev;
|
||||
int ocx, ocy, newscreen;
|
||||
area_t geometry;
|
||||
Client *c = globalconf.focus->client, *target;
|
||||
Layout *layout = layout_get_current(screen);
|
||||
SimpleWindow *sw = NULL;
|
||||
DrawCtx *ctx;
|
||||
style_t style;
|
||||
bool ignore_motion_events = false;
|
||||
xcb_generic_event_t *ev = NULL;
|
||||
xcb_motion_notify_event_t *ev_motion = NULL;
|
||||
xcb_grab_pointer_reply_t *grab_pointer_r = NULL;
|
||||
xcb_query_pointer_reply_t *query_pointer_r = NULL, *mquery_pointer_r = NULL;
|
||||
|
||||
if(!c
|
||||
|| XGrabPointer(globalconf.display,
|
||||
RootWindow(globalconf.display, c->phys_screen),
|
||||
False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
|
||||
RootWindow(globalconf.display, c->phys_screen),
|
||||
globalconf.cursor[CurMove], CurrentTime) != GrabSuccess)
|
||||
|| xcb_grab_pointer_reply(globalconf.connection,
|
||||
xcb_grab_pointer(globalconf.connection, false,
|
||||
root_window(globalconf.connection, c->phys_screen),
|
||||
MOUSEMASK, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC,
|
||||
root_window(globalconf.connection, c->phys_screen),
|
||||
globalconf.cursor[CurMove], XCB_CURRENT_TIME),
|
||||
NULL))
|
||||
return;
|
||||
|
||||
XQueryPointer(globalconf.display,
|
||||
RootWindow(globalconf.display, c->phys_screen),
|
||||
&dummy, &dummy, &x, &y, &di, &di, &dui);
|
||||
query_pointer_r = xcb_query_pointer_reply(globalconf.connection,
|
||||
xcb_query_pointer_unchecked(globalconf.connection,
|
||||
root_window(globalconf.connection, c->phys_screen)),
|
||||
NULL);
|
||||
|
||||
geometry = c->geometry;
|
||||
ocx = geometry.x;
|
||||
ocy = geometry.y;
|
||||
c->ismax = False;
|
||||
c->ismax = false;
|
||||
|
||||
style = globalconf.screens[c->screen].styles.focus;
|
||||
|
||||
if(c->isfloating || layout->arrange == layout_floating)
|
||||
{
|
||||
sw = simplewindow_new(globalconf.display, c->phys_screen, 0, 0,
|
||||
draw_textwidth(globalconf.display,
|
||||
sw = simplewindow_new(globalconf.connection, c->phys_screen, 0, 0,
|
||||
draw_textwidth(globalconf.connection,
|
||||
globalconf.default_screen,
|
||||
globalconf.screens[c->screen].styles.focus.font,
|
||||
"0000x0000+0000+0000") + style.font->height,
|
||||
1.5 * style.font->height, 0);
|
||||
|
||||
ctx = draw_context_new(globalconf.display, sw->phys_screen,
|
||||
ctx = draw_context_new(globalconf.connection, sw->phys_screen,
|
||||
sw->geometry.width, sw->geometry.height,
|
||||
sw->drawable);
|
||||
XMapRaised(globalconf.display, sw->window);
|
||||
xutil_map_raised(globalconf.connection, sw->window);
|
||||
mouse_resizebar_draw(ctx, style, sw, geometry, c->border);
|
||||
}
|
||||
|
||||
p_delete(&grab_pointer_r);
|
||||
|
||||
for(;;)
|
||||
{
|
||||
XMaskEvent(globalconf.display, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
|
||||
switch (ev.type)
|
||||
/* TODO: need a review
|
||||
*
|
||||
* XMaskEvent allows to retrieve only specified events from
|
||||
* the queue and requeue the other events...
|
||||
*/
|
||||
while((ev = xcb_poll_for_event(globalconf.connection)))
|
||||
{
|
||||
case ButtonRelease:
|
||||
XUngrabPointer(globalconf.display, CurrentTime);
|
||||
switch((ev->response_type & 0x7f))
|
||||
{
|
||||
case XCB_BUTTON_RELEASE:
|
||||
xcb_ungrab_pointer(globalconf.connection, XCB_CURRENT_TIME);
|
||||
if(sw)
|
||||
{
|
||||
draw_context_delete(&ctx);
|
||||
simplewindow_delete(&sw);
|
||||
}
|
||||
|
||||
p_delete(&query_pointer_r);
|
||||
p_delete(&ev);
|
||||
return;
|
||||
case ConfigureRequest:
|
||||
event_handle_configurerequest(&ev);
|
||||
case XCB_MOTION_NOTIFY:
|
||||
if(ignore_motion_events)
|
||||
break;
|
||||
case Expose:
|
||||
event_handle_expose(&ev);
|
||||
break;
|
||||
case MapRequest:
|
||||
event_handle_maprequest(&ev);
|
||||
break;
|
||||
case EnterNotify:
|
||||
event_handle_enternotify(&ev);
|
||||
break;
|
||||
case MotionNotify:
|
||||
|
||||
if(c->isfloating || layout->arrange == layout_floating)
|
||||
{
|
||||
geometry.x = ocx + (ev.xmotion.x - x);
|
||||
geometry.y = ocy + (ev.xmotion.y - y);
|
||||
ev_motion = (xcb_motion_notify_event_t *) ev;
|
||||
|
||||
geometry.x = ocx + (ev_motion->event_x - query_pointer_r->root_x);
|
||||
geometry.y = ocy + (ev_motion->event_y - query_pointer_r->root_y);
|
||||
|
||||
geometry = mouse_snapclient(c, geometry);
|
||||
|
||||
c->ismoving = True;
|
||||
client_resize(c, geometry, False);
|
||||
c->ismoving = False;
|
||||
if(sw)
|
||||
mouse_resizebar_draw(ctx, style, sw, c->geometry, c->border);
|
||||
|
||||
p_delete(&ev);
|
||||
}
|
||||
else
|
||||
{
|
||||
XQueryPointer(globalconf.display,
|
||||
RootWindow(globalconf.display, c->phys_screen),
|
||||
&dummy, &child, &x, &y, &di, &di, &dui);
|
||||
if((newscreen = screen_get_bycoord(globalconf.screens_info, c->screen, x, y)) != c->screen)
|
||||
mquery_pointer_r = xcb_query_pointer_reply(globalconf.connection,
|
||||
xcb_query_pointer_unchecked(globalconf.connection,
|
||||
root_window(globalconf.connection, c->phys_screen)),
|
||||
NULL);
|
||||
if((newscreen = screen_get_bycoord(globalconf.screens_info, c->screen,
|
||||
mquery_pointer_r->root_x,
|
||||
mquery_pointer_r->root_y)) != c->screen)
|
||||
{
|
||||
move_client_to_screen(c, newscreen, True);
|
||||
globalconf.screens[c->screen].need_arrange = True;
|
||||
if(layout_get_current(newscreen)->arrange != layout_floating)
|
||||
globalconf.screens[newscreen].need_arrange = True;
|
||||
move_client_to_screen(c, newscreen, true);
|
||||
globalconf.screens[c->screen].need_arrange = true;
|
||||
globalconf.screens[newscreen].need_arrange = true;
|
||||
layout_refresh();
|
||||
}
|
||||
if((target = client_get_bywin(globalconf.clients, child))
|
||||
if((target = client_get_bywin(globalconf.clients, mquery_pointer_r->child))
|
||||
&& target != c && !target->isfloating)
|
||||
{
|
||||
client_list_swap(&globalconf.clients, c, target);
|
||||
globalconf.screens[c->screen].need_arrange = True;
|
||||
globalconf.screens[c->screen].need_arrange = true;
|
||||
layout_refresh();
|
||||
}
|
||||
|
||||
p_delete(&mquery_pointer_r);
|
||||
}
|
||||
while(XCheckMaskEvent(globalconf.display, PointerMotionMask, &ev));
|
||||
ignore_motion_events = true;
|
||||
break;
|
||||
case XCB_CONFIGURE_REQUEST:
|
||||
case XCB_EXPOSE:
|
||||
case XCB_MAP_REQUEST:
|
||||
case XCB_ENTER_NOTIFY:
|
||||
/* Handle errors */
|
||||
case 0:
|
||||
xcb_handle_event(globalconf.evenths, ev);
|
||||
break;
|
||||
}
|
||||
|
||||
p_delete(&ev);
|
||||
}
|
||||
}
|
||||
|
||||
p_delete(&query_pointer_r);
|
||||
}
|
||||
|
||||
/** Resize the focused window with the mouse.
|
||||
* \param screen Screen ID
|
||||
* \param arg Unused
|
||||
|
@ -253,7 +279,9 @@ void
|
|||
uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused)))
|
||||
{
|
||||
int ocx = 0, ocy = 0, n;
|
||||
XEvent ev;
|
||||
xcb_generic_event_t *ev = NULL;
|
||||
xcb_motion_notify_event_t *ev_motion = NULL;
|
||||
bool ignore_motion_events = false;
|
||||
Client *c = globalconf.focus->client;
|
||||
Tag **curtags = tags_get_current(screen);
|
||||
Layout *layout = curtags[0]->layout;
|
||||
|
@ -262,6 +290,8 @@ uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused)))
|
|||
SimpleWindow *sw = NULL;
|
||||
DrawCtx *ctx = NULL;
|
||||
style_t style;
|
||||
xcb_grab_pointer_cookie_t grab_pointer_c;
|
||||
xcb_grab_pointer_reply_t *grab_pointer_r = NULL;
|
||||
|
||||
/* only handle floating and tiled layouts */
|
||||
if(!c || c->isfixed)
|
||||
|
@ -273,19 +303,20 @@ uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused)))
|
|||
{
|
||||
ocx = c->geometry.x;
|
||||
ocy = c->geometry.y;
|
||||
c->ismax = False;
|
||||
c->ismax = false;
|
||||
|
||||
sw = simplewindow_new(globalconf.display, c->phys_screen, 0, 0,
|
||||
draw_textwidth(globalconf.display,
|
||||
sw = simplewindow_new(globalconf.connection, c->phys_screen, 0, 0,
|
||||
draw_textwidth(globalconf.connection,
|
||||
globalconf.default_screen,
|
||||
globalconf.screens[c->screen].styles.focus.font,
|
||||
"0000x0000+0000+0000") + style.font->height,
|
||||
1.5 * style.font->height, 0);
|
||||
|
||||
ctx = draw_context_new(globalconf.display, sw->phys_screen,
|
||||
ctx = draw_context_new(globalconf.connection, sw->phys_screen,
|
||||
sw->geometry.width, sw->geometry.height,
|
||||
sw->drawable);
|
||||
XMapRaised(globalconf.display, sw->window);
|
||||
mouse_resizebar_draw(ctx, style, sw, c->geometry, c->border);
|
||||
xutil_map_raised(globalconf.connection, sw->window);
|
||||
mouse_resizebar_draw(ctx, style, sw, geometry, c->border);
|
||||
}
|
||||
else if (layout->arrange == layout_tile || layout->arrange == layout_tileleft
|
||||
|| layout->arrange == layout_tilebottom || layout->arrange == layout_tiletop)
|
||||
|
@ -306,58 +337,68 @@ uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused)))
|
|||
else
|
||||
return;
|
||||
|
||||
if(XGrabPointer(globalconf.display,
|
||||
RootWindow(globalconf.display, c->phys_screen),
|
||||
False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
|
||||
RootWindow(globalconf.display, c->phys_screen),
|
||||
globalconf.cursor[CurResize], CurrentTime) != GrabSuccess)
|
||||
grab_pointer_c = xcb_grab_pointer(globalconf.connection, false,
|
||||
root_window(globalconf.connection, c->phys_screen),
|
||||
MOUSEMASK, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC,
|
||||
root_window(globalconf.connection, c->phys_screen),
|
||||
globalconf.cursor[CurResize], XCB_CURRENT_TIME);
|
||||
|
||||
if((grab_pointer_r = xcb_grab_pointer_reply(globalconf.connection,
|
||||
grab_pointer_c, NULL)) == NULL)
|
||||
return;
|
||||
|
||||
p_delete(&grab_pointer_r);
|
||||
|
||||
if(curtags[0]->layout->arrange == layout_tileleft)
|
||||
XWarpPointer(globalconf.display, None, c->win, 0, 0, 0, 0, 0,
|
||||
c->geometry.height + c->border - 1);
|
||||
xcb_warp_pointer(globalconf.connection, XCB_NONE, c->win, 0, 0,
|
||||
0, 0, 0, c->geometry.height + c->border - 1);
|
||||
else if(curtags[0]->layout->arrange == layout_tilebottom)
|
||||
XWarpPointer(globalconf.display, None, c->win, 0, 0, 0, 0,
|
||||
c->geometry.width + c->border - 1, c->geometry.height + c->border - 1);
|
||||
xcb_warp_pointer(globalconf.connection, XCB_NONE, c->win,
|
||||
0, 0, 0, 0, c->geometry.width + c->border - 1,
|
||||
c->geometry.height + c->border - 1);
|
||||
else if(curtags[0]->layout->arrange == layout_tiletop)
|
||||
XWarpPointer(globalconf.display, None, c->win, 0, 0, 0, 0,
|
||||
c->geometry.width + c->border - 1, 0);
|
||||
xcb_warp_pointer(globalconf.connection, XCB_NONE, c->win, 0, 0,
|
||||
0, 0, c->geometry.width + c->border - 1, 0);
|
||||
else
|
||||
XWarpPointer(globalconf.display, None, c->win, 0, 0, 0, 0,
|
||||
c->geometry.width + c->border - 1, c->geometry.height + c->border - 1);
|
||||
xcb_warp_pointer(globalconf.connection, XCB_NONE, c->win, 0, 0,
|
||||
0, 0, c->geometry.width + c->border - 1,
|
||||
c->geometry.height + c->border - 1);
|
||||
|
||||
for(;;)
|
||||
{
|
||||
XMaskEvent(globalconf.display, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
|
||||
switch (ev.type)
|
||||
/* TODO: need a review
|
||||
*
|
||||
* XMaskEvent allows to retrieve only specified events from
|
||||
* the queue and requeue the other events...
|
||||
*/
|
||||
while((ev = xcb_poll_for_event(globalconf.connection)))
|
||||
{
|
||||
case ButtonRelease:
|
||||
XUngrabPointer(globalconf.display, CurrentTime);
|
||||
switch((ev->response_type & 0x7f))
|
||||
{
|
||||
case XCB_BUTTON_RELEASE:
|
||||
if(sw)
|
||||
{
|
||||
draw_context_delete(&ctx);
|
||||
simplewindow_delete(&sw);
|
||||
}
|
||||
xcb_ungrab_pointer(globalconf.connection, XCB_CURRENT_TIME);
|
||||
p_delete(&ev);
|
||||
return;
|
||||
case ConfigureRequest:
|
||||
event_handle_configurerequest(&ev);
|
||||
case XCB_MOTION_NOTIFY:
|
||||
if(ignore_motion_events)
|
||||
break;
|
||||
case Expose:
|
||||
event_handle_expose(&ev);
|
||||
break;
|
||||
case MapRequest:
|
||||
event_handle_maprequest(&ev);
|
||||
break;
|
||||
case MotionNotify:
|
||||
|
||||
ev_motion = (xcb_motion_notify_event_t *) ev;
|
||||
|
||||
if(layout->arrange == layout_floating || c->isfloating)
|
||||
{
|
||||
if((geometry.width = ev.xmotion.x - ocx - 2 * c->border + 1) <= 0)
|
||||
if((geometry.width = ev_motion->event_x - ocx - 2 * c->border + 1) <= 0)
|
||||
geometry.width = 1;
|
||||
if((geometry.height = ev.xmotion.y - ocy - 2 * c->border + 1) <= 0)
|
||||
if((geometry.height = ev_motion->event_y - ocy - 2 * c->border + 1) <= 0)
|
||||
geometry.height = 1;
|
||||
geometry.x = c->geometry.x;
|
||||
geometry.y = c->geometry.y;
|
||||
client_resize(c, geometry, True);
|
||||
client_resize(c, geometry, true);
|
||||
if(sw)
|
||||
mouse_resizebar_draw(ctx, style, sw, c->geometry, c->border);
|
||||
}
|
||||
|
@ -365,25 +406,35 @@ uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused)))
|
|||
|| layout->arrange == layout_tiletop || layout->arrange == layout_tilebottom)
|
||||
{
|
||||
if(layout->arrange == layout_tile)
|
||||
mwfact = (double) (ev.xmotion.x - area.x) / area.width;
|
||||
mwfact = (double) (ev_motion->event_x - area.x) / area.width;
|
||||
else if(curtags[0]->layout->arrange == layout_tileleft)
|
||||
mwfact = 1 - (double) (ev.xmotion.x - area.x) / area.width;
|
||||
mwfact = 1 - (double) (ev_motion->event_x - area.x) / area.width;
|
||||
else if(curtags[0]->layout->arrange == layout_tilebottom)
|
||||
mwfact = (double) (ev.xmotion.y - area.y) / area.height;
|
||||
mwfact = (double) (ev_motion->event_y - area.y) / area.height;
|
||||
else
|
||||
mwfact = 1 - (double) (ev.xmotion.y - area.y) / area.height;
|
||||
mwfact = 1 - (double) (ev_motion->event_y - area.y) / area.height;
|
||||
mwfact = MAX(globalconf.screens[screen].mwfact_lower_limit,
|
||||
MIN(globalconf.screens[screen].mwfact_upper_limit, mwfact));
|
||||
if(fabs(curtags[0]->mwfact - mwfact) >= 0.01)
|
||||
{
|
||||
curtags[0]->mwfact = mwfact;
|
||||
globalconf.screens[screen].need_arrange = True;
|
||||
globalconf.screens[screen].need_arrange = true;
|
||||
layout_refresh();
|
||||
while(XCheckMaskEvent(globalconf.display, PointerMotionMask, &ev));
|
||||
ignore_motion_events = true;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case XCB_CONFIGURE_REQUEST:
|
||||
case XCB_EXPOSE:
|
||||
case XCB_MAP_REQUEST:
|
||||
/* Handle errors */
|
||||
case 0:
|
||||
xcb_handle_event(globalconf.evenths, ev);
|
||||
break;
|
||||
}
|
||||
|
||||
p_delete(&ev);
|
||||
}
|
||||
}
|
||||
p_delete(&curtags);
|
||||
|
|
18
placement.c
18
placement.c
|
@ -68,7 +68,7 @@ placement_smart(Client *c)
|
|||
Client *client;
|
||||
area_t newgeometry = { 0, 0, 0, 0, NULL, NULL };
|
||||
area_t *screen_geometry, *arealist = NULL, *r;
|
||||
Bool found = False;
|
||||
bool found = false;
|
||||
Layout *layout;
|
||||
|
||||
screen_geometry = p_new(area_t, 1);
|
||||
|
@ -101,7 +101,7 @@ placement_smart(Client *c)
|
|||
if(r->width >= c->f_geometry.width && r->height >= c->f_geometry.height
|
||||
&& r->width * r->height > newgeometry.width * newgeometry.height)
|
||||
{
|
||||
found = True;
|
||||
found = true;
|
||||
newgeometry = *r;
|
||||
}
|
||||
|
||||
|
@ -128,16 +128,16 @@ placement_smart(Client *c)
|
|||
area_t
|
||||
placement_under_mouse(Client *c)
|
||||
{
|
||||
Window dummy;
|
||||
unsigned int m;
|
||||
int x, y, d;
|
||||
xcb_query_pointer_reply_t *xqp;
|
||||
area_t finalgeometry = c->f_geometry;
|
||||
|
||||
if(XQueryPointer(globalconf.display, RootWindow(globalconf.display, c->phys_screen),
|
||||
&dummy, &dummy, &x, &y, &d, &d, &m))
|
||||
if((xqp = xcb_query_pointer_reply(globalconf.connection,
|
||||
xcb_query_pointer(globalconf.connection,
|
||||
root_window(globalconf.connection, c->phys_screen)),
|
||||
NULL)) != NULL)
|
||||
{
|
||||
finalgeometry.x = x - c->f_geometry.width / 2;
|
||||
finalgeometry.y = y - c->f_geometry.height / 2;
|
||||
finalgeometry.x = xqp->root_x - c->f_geometry.width / 2;
|
||||
finalgeometry.y = xqp->root_y - c->f_geometry.height / 2;
|
||||
}
|
||||
|
||||
finalgeometry = titlebar_geometry_add(&c->titlebar, finalgeometry);
|
||||
|
|
38
rules.c
38
rules.c
|
@ -19,8 +19,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
#include "rules.h"
|
||||
#include "common/xutil.h"
|
||||
|
||||
|
@ -43,59 +41,63 @@ rules_compile_regex(char *val)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static Bool
|
||||
static bool
|
||||
client_match_rule(Client *c, Rule *r)
|
||||
{
|
||||
char *prop, buf[512];
|
||||
regmatch_t tmp;
|
||||
ssize_t len;
|
||||
XClassHint ch = { 0, 0 };
|
||||
Bool ret = False;
|
||||
class_hint_t *ch = NULL;
|
||||
bool ret = false;
|
||||
|
||||
if(r->prop_r)
|
||||
{
|
||||
/* first try to match on name */
|
||||
XGetClassHint(globalconf.display, c->win, &ch);
|
||||
ch = x_get_class_hint(globalconf.connection, c->win);
|
||||
if (!ch)
|
||||
return false;
|
||||
|
||||
len = a_strlen(ch.res_class) + a_strlen(ch.res_name) + a_strlen(c->name);
|
||||
len = a_strlen(ch->res_class) + a_strlen(ch->res_name) + a_strlen(c->name);
|
||||
prop = p_new(char, len + 3);
|
||||
|
||||
/* rule matching */
|
||||
snprintf(prop, len + 3, "%s:%s:%s",
|
||||
ch.res_class ? ch.res_class : "", ch.res_name ? ch.res_name : "", c->name);
|
||||
ch->res_class ? ch->res_class : "", ch->res_name ? ch->res_name : "", c->name);
|
||||
|
||||
ret = !regexec(r->prop_r, prop, 1, &tmp, 0);
|
||||
|
||||
p_delete(&prop);
|
||||
|
||||
if(ch.res_class)
|
||||
XFree(ch.res_class);
|
||||
if(ch.res_name)
|
||||
XFree(ch.res_name);
|
||||
if(ch->res_class)
|
||||
p_delete(&ch->res_class);
|
||||
if(ch->res_name)
|
||||
p_delete(&ch->res_name);
|
||||
|
||||
p_delete(&ch);
|
||||
|
||||
if(ret)
|
||||
return True;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(r->xprop
|
||||
&& r->xpropval_r
|
||||
&& xgettextprop(globalconf.display, c->win,
|
||||
XInternAtom(globalconf.display, r->xprop, False),
|
||||
&& xgettextprop(globalconf.connection, c->win,
|
||||
x_intern_atom(globalconf.connection, r->xprop),
|
||||
buf, ssizeof(buf)))
|
||||
ret = !regexec(r->xpropval_r, buf, 1, &tmp, 0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Bool
|
||||
bool
|
||||
tag_match_rule(Tag *t, Rule *r)
|
||||
{
|
||||
regmatch_t tmp;
|
||||
|
||||
if(r->tags_r && !regexec(r->tags_r, t->name, 1, &tmp, 0))
|
||||
return True;
|
||||
return true;
|
||||
|
||||
return False;
|
||||
return false;
|
||||
}
|
||||
|
||||
Rule *
|
||||
|
|
2
rules.h
2
rules.h
|
@ -27,7 +27,7 @@
|
|||
#define RULE_NOSCREEN -1
|
||||
|
||||
regex_t * rules_compile_regex(char *);
|
||||
Bool tag_match_rule(Tag *, Rule *);
|
||||
bool tag_match_rule(Tag *, Rule *);
|
||||
Fuzzy rules_get_fuzzy_from_str(const char *);
|
||||
Rule * rule_matching_client(Client *);
|
||||
|
||||
|
|
44
screen.c
44
screen.c
|
@ -19,6 +19,11 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_aux.h>
|
||||
|
||||
#include "screen.h"
|
||||
#include "tag.h"
|
||||
#include "focus.h"
|
||||
|
@ -79,9 +84,10 @@ get_display_area(int screen, Statusbar *statusbar, Padding *padding)
|
|||
{
|
||||
area_t area = { 0, 0, 0, 0, NULL, NULL };
|
||||
Statusbar *sb;
|
||||
xcb_screen_t *s = xcb_aux_get_screen(globalconf.connection, screen);
|
||||
|
||||
area.width = DisplayWidth(globalconf.display, screen);
|
||||
area.height = DisplayHeight(globalconf.display, screen);
|
||||
area.width = s->width_in_pixels;
|
||||
area.height = s->height_in_pixels;
|
||||
|
||||
for(sb = statusbar; sb; sb = sb->next)
|
||||
{
|
||||
|
@ -109,18 +115,18 @@ int
|
|||
screen_virttophys(int screen)
|
||||
{
|
||||
if(globalconf.screens_info->xinerama_is_active)
|
||||
return DefaultScreen(globalconf.display);
|
||||
return globalconf.default_screen;
|
||||
return screen;
|
||||
}
|
||||
|
||||
/** Move a client to a virtual screen
|
||||
* \param c the client
|
||||
* \param new_screen The destinatiuon screen
|
||||
* \param doresize set to True if we also move the client to the new x and
|
||||
* \param doresize set to true if we also move the client to the new x and
|
||||
* y of the new screen
|
||||
*/
|
||||
void
|
||||
move_client_to_screen(Client *c, int new_screen, Bool doresize)
|
||||
move_client_to_screen(Client *c, int new_screen, bool doresize)
|
||||
{
|
||||
Tag *tag;
|
||||
int old_screen = c->screen;
|
||||
|
@ -189,17 +195,17 @@ move_client_to_screen(Client *c, int new_screen, Bool doresize)
|
|||
if(c->m_geometry.y + c->m_geometry.height >= to.y + to.height)
|
||||
c->m_geometry.y = to.y + to.height - c->m_geometry.height - 2 * c->border;
|
||||
|
||||
client_resize(c, new_geometry, False);
|
||||
client_resize(c, new_geometry, false);
|
||||
}
|
||||
/* if floating, move to this new coords */
|
||||
else if(c->isfloating)
|
||||
client_resize(c, new_f_geometry, False);
|
||||
client_resize(c, new_f_geometry, false);
|
||||
/* otherwise just register them */
|
||||
else
|
||||
{
|
||||
c->f_geometry = new_f_geometry;
|
||||
globalconf.screens[old_screen].need_arrange = True;
|
||||
globalconf.screens[c->screen].need_arrange = True;
|
||||
globalconf.screens[old_screen].need_arrange = true;
|
||||
globalconf.screens[c->screen].need_arrange = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -210,18 +216,20 @@ move_client_to_screen(Client *c, int new_screen, Bool doresize)
|
|||
static void
|
||||
move_mouse_pointer_to_screen(int phys_screen)
|
||||
{
|
||||
xcb_screen_t *s = xcb_aux_get_screen(globalconf.connection, phys_screen);
|
||||
|
||||
if(globalconf.screens_info->xinerama_is_active)
|
||||
{
|
||||
area_t area = screen_get_area(phys_screen, NULL, NULL);
|
||||
XWarpPointer(globalconf.display,
|
||||
None,
|
||||
DefaultRootWindow(globalconf.display),
|
||||
xcb_warp_pointer(globalconf.connection,
|
||||
XCB_NONE,
|
||||
s->root,
|
||||
0, 0, 0, 0, area.x, area.y);
|
||||
}
|
||||
else
|
||||
XWarpPointer(globalconf.display,
|
||||
None,
|
||||
RootWindow(globalconf.display, phys_screen),
|
||||
xcb_warp_pointer(globalconf.connection,
|
||||
XCB_NONE,
|
||||
root_window(globalconf.connection, phys_screen),
|
||||
0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
|
@ -247,7 +255,7 @@ uicb_screen_focus(int screen, char *arg)
|
|||
if (new_screen > (globalconf.screens_info->nscreen - 1))
|
||||
new_screen = 0;
|
||||
|
||||
client_focus(NULL, new_screen, True);
|
||||
client_focus(NULL, new_screen, true);
|
||||
|
||||
move_mouse_pointer_to_screen(new_screen);
|
||||
}
|
||||
|
@ -278,8 +286,8 @@ uicb_client_movetoscreen(int screen __attribute__ ((unused)), char *arg)
|
|||
new_screen = globalconf.screens_info->nscreen - 1;
|
||||
|
||||
prev_screen = sel->screen;
|
||||
move_client_to_screen(sel, new_screen, True);
|
||||
move_client_to_screen(sel, new_screen, true);
|
||||
move_mouse_pointer_to_screen(new_screen);
|
||||
client_focus(sel, sel->screen, True);
|
||||
client_focus(sel, sel->screen, true);
|
||||
}
|
||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||
|
|
2
screen.h
2
screen.h
|
@ -27,7 +27,7 @@
|
|||
area_t screen_get_area(int, Statusbar *, Padding *);
|
||||
area_t get_display_area(int, Statusbar *, Padding *);
|
||||
int screen_virttophys(int);
|
||||
void move_client_to_screen(Client *, int, Bool);
|
||||
void move_client_to_screen(Client *, int, bool);
|
||||
|
||||
Uicb uicb_screen_focus;
|
||||
Uicb uicb_client_movetoscreen;
|
||||
|
|
38
statusbar.c
38
statusbar.c
|
@ -21,6 +21,8 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_aux.h>
|
||||
|
||||
#include "statusbar.h"
|
||||
#include "screen.h"
|
||||
|
@ -38,11 +40,11 @@ statusbar_position_update(Statusbar *statusbar)
|
|||
|
||||
if(statusbar->position == Off)
|
||||
{
|
||||
XUnmapWindow(globalconf.display, statusbar->sw->window);
|
||||
xcb_unmap_window(globalconf.connection, statusbar->sw->window);
|
||||
return;
|
||||
}
|
||||
|
||||
XMapRaised(globalconf.display, statusbar->sw->window);
|
||||
xutil_map_raised(globalconf.connection, statusbar->sw->window);
|
||||
|
||||
/* Top and Bottom Statusbar have prio */
|
||||
if(statusbar->position == Top || statusbar->position == Bottom)
|
||||
|
@ -113,13 +115,13 @@ statusbar_draw(Statusbar *statusbar)
|
|||
|
||||
rectangle.width = statusbar->width;
|
||||
rectangle.height = statusbar->height;
|
||||
draw_rectangle(statusbar->ctx, rectangle, 1.0, True,
|
||||
draw_rectangle(statusbar->ctx, rectangle, 1.0, true,
|
||||
globalconf.screens[statusbar->screen].styles.normal.bg);
|
||||
|
||||
for(widget = statusbar->widgets; widget; widget = widget->next)
|
||||
if (widget->alignment == AlignLeft)
|
||||
{
|
||||
widget->cache.needs_update = False;
|
||||
widget->cache.needs_update = false;
|
||||
left += widget->draw(widget, statusbar->ctx, left, (left + right));
|
||||
}
|
||||
|
||||
|
@ -129,14 +131,14 @@ statusbar_draw(Statusbar *statusbar)
|
|||
widget = widget_list_prev(&statusbar->widgets, widget))
|
||||
if (widget->alignment == AlignRight)
|
||||
{
|
||||
widget->cache.needs_update = False;
|
||||
widget->cache.needs_update = false;
|
||||
right += widget->draw(widget, statusbar->ctx, right, (left + right));
|
||||
}
|
||||
|
||||
for(widget = statusbar->widgets; widget; widget = widget->next)
|
||||
if (widget->alignment == AlignFlex)
|
||||
{
|
||||
widget->cache.needs_update = False;
|
||||
widget->cache.needs_update = false;
|
||||
left += widget->draw(widget, statusbar->ctx, left, (left + right));
|
||||
}
|
||||
|
||||
|
@ -181,7 +183,8 @@ void
|
|||
statusbar_init(Statusbar *statusbar)
|
||||
{
|
||||
Statusbar *sb;
|
||||
Drawable dw;
|
||||
xcb_drawable_t dw;
|
||||
xcb_screen_t *s = NULL;
|
||||
int phys_screen = screen_virttophys(statusbar->screen);
|
||||
area_t area = screen_get_area(statusbar->screen,
|
||||
globalconf.screens[statusbar->screen].statusbar,
|
||||
|
@ -214,12 +217,12 @@ statusbar_init(Statusbar *statusbar)
|
|||
case Right:
|
||||
case Left:
|
||||
statusbar->sw =
|
||||
simplewindow_new(globalconf.display, phys_screen, 0, 0,
|
||||
simplewindow_new(globalconf.connection, phys_screen, 0, 0,
|
||||
statusbar->height, statusbar->width, 0);
|
||||
break;
|
||||
default:
|
||||
statusbar->sw =
|
||||
simplewindow_new(globalconf.display, phys_screen, 0, 0,
|
||||
simplewindow_new(globalconf.connection, phys_screen, 0, 0,
|
||||
statusbar->width, statusbar->height, 0);
|
||||
break;
|
||||
}
|
||||
|
@ -234,19 +237,22 @@ statusbar_init(Statusbar *statusbar)
|
|||
return;
|
||||
case Right:
|
||||
case Left:
|
||||
s = xcb_aux_get_screen(globalconf.connection, phys_screen);
|
||||
|
||||
/* we need a new pixmap this way [ ] to render */
|
||||
dw = XCreatePixmap(globalconf.display,
|
||||
RootWindow(globalconf.display, phys_screen),
|
||||
statusbar->width, statusbar->height,
|
||||
DefaultDepth(globalconf.display, phys_screen));
|
||||
statusbar->ctx = draw_context_new(globalconf.display,
|
||||
dw = xcb_generate_id(globalconf.connection);
|
||||
xcb_create_pixmap(globalconf.connection,
|
||||
s->root_depth, dw,
|
||||
root_window(globalconf.connection, phys_screen),
|
||||
statusbar->width, statusbar->height);
|
||||
statusbar->ctx = draw_context_new(globalconf.connection,
|
||||
phys_screen,
|
||||
statusbar->width,
|
||||
statusbar->height,
|
||||
dw);
|
||||
break;
|
||||
default:
|
||||
statusbar->ctx = draw_context_new(globalconf.display,
|
||||
statusbar->ctx = draw_context_new(globalconf.connection,
|
||||
phys_screen,
|
||||
statusbar->width,
|
||||
statusbar->height,
|
||||
|
@ -297,7 +303,7 @@ statusbar_toggle(Statusbar *statusbar)
|
|||
else
|
||||
statusbar->position = Off;
|
||||
|
||||
globalconf.screens[statusbar->screen].need_arrange = True;
|
||||
globalconf.screens[statusbar->screen].need_arrange = true;
|
||||
}
|
||||
|
||||
/** Toggle the statusbar on or off.
|
||||
|
|
94
structs.h
94
structs.h
|
@ -22,6 +22,8 @@
|
|||
#ifndef AWESOME_STRUCTS_H
|
||||
#define AWESOME_STRUCTS_H
|
||||
|
||||
#include <xcb/xcb_event.h>
|
||||
|
||||
#include <regex.h>
|
||||
#include "layout.h"
|
||||
#include "common/draw.h"
|
||||
|
@ -42,8 +44,8 @@ typedef enum
|
|||
/** Rules for floating rule */
|
||||
typedef enum
|
||||
{
|
||||
No = False,
|
||||
Yes = True,
|
||||
No = false,
|
||||
Yes = true,
|
||||
Maybe
|
||||
} Fuzzy;
|
||||
|
||||
|
@ -91,8 +93,8 @@ typedef struct Key Key;
|
|||
struct Key
|
||||
{
|
||||
unsigned long mod;
|
||||
KeySym keysym;
|
||||
KeyCode keycode;
|
||||
xcb_keysym_t keysym;
|
||||
xcb_keycode_t keycode;
|
||||
Uicb *func;
|
||||
char *arg;
|
||||
/** Next and previous keys */
|
||||
|
@ -136,16 +138,16 @@ struct Widget
|
|||
/** Update function */
|
||||
widget_tell_status_t (*tell)(Widget *, char *, char *);
|
||||
/** ButtonPressedEvent handler */
|
||||
void (*button_press)(Widget *, XButtonPressedEvent *);
|
||||
void (*button_press)(Widget *, xcb_button_press_event_t *);
|
||||
/** Statusbar */
|
||||
Statusbar *statusbar;
|
||||
/** Alignement */
|
||||
Alignment alignment;
|
||||
/** Misc private data */
|
||||
void *data;
|
||||
/** True if user supplied coords */
|
||||
Bool user_supplied_x;
|
||||
Bool user_supplied_y;
|
||||
/** true if user supplied coords */
|
||||
bool user_supplied_x;
|
||||
bool user_supplied_y;
|
||||
/** area_t */
|
||||
area_t area;
|
||||
/** Buttons bindings */
|
||||
|
@ -153,7 +155,7 @@ struct Widget
|
|||
/** Cache */
|
||||
struct
|
||||
{
|
||||
Bool needs_update;
|
||||
bool needs_update;
|
||||
int flags;
|
||||
} cache;
|
||||
/** Next and previous widgets */
|
||||
|
@ -203,31 +205,31 @@ struct Client
|
|||
int minax, maxax, minay, maxay;
|
||||
int border, oldborder;
|
||||
/** Has urgency hint */
|
||||
Bool isurgent;
|
||||
bool isurgent;
|
||||
/** Store previous floating state before maximizing */
|
||||
Bool wasfloating;
|
||||
/** True if the window is floating */
|
||||
Bool isfloating;
|
||||
/** True if the window is fixed */
|
||||
Bool isfixed;
|
||||
/** True if the window is maximized */
|
||||
Bool ismax;
|
||||
/** True if the client must be skipped from client list */
|
||||
Bool skip;
|
||||
/** True if the client is moving */
|
||||
Bool ismoving;
|
||||
/** True if the client must be skipped from task bar client list */
|
||||
Bool skiptb;
|
||||
bool wasfloating;
|
||||
/** true if the window is floating */
|
||||
bool isfloating;
|
||||
/** true if the window is fixed */
|
||||
bool isfixed;
|
||||
/** true if the window is maximized */
|
||||
bool ismax;
|
||||
/** true if the client must be skipped from client list */
|
||||
bool skip;
|
||||
/** true if the client is moving */
|
||||
bool ismoving;
|
||||
/** true if the client must be skipped from task bar client list */
|
||||
bool skiptb;
|
||||
/** Next and previous clients */
|
||||
Client *prev, *next;
|
||||
/** Window of the client */
|
||||
Window win;
|
||||
xcb_window_t win;
|
||||
/** Client logical screen */
|
||||
int screen;
|
||||
/** Client physical screen */
|
||||
int phys_screen;
|
||||
/** True if the client is a new one */
|
||||
Bool newcomer;
|
||||
bool newcomer;
|
||||
/** Titlebar */
|
||||
Titlebar titlebar;
|
||||
/** layer in the stacking order */
|
||||
|
@ -251,10 +253,10 @@ struct Tag
|
|||
char *name;
|
||||
/** Screen */
|
||||
int screen;
|
||||
/** True if selected */
|
||||
Bool selected;
|
||||
/** True if was selected before selecting others tags */
|
||||
Bool was_selected;
|
||||
/** true if selected */
|
||||
bool selected;
|
||||
/** true if was selected before selecting others tags */
|
||||
bool was_selected;
|
||||
/** Current tag layout */
|
||||
Layout *layout;
|
||||
/** Master width factor */
|
||||
|
@ -304,17 +306,17 @@ typedef struct
|
|||
/** Floating window placement algo */
|
||||
FloatingPlacement *floating_placement;
|
||||
/** Respect resize hints */
|
||||
Bool resize_hints;
|
||||
bool resize_hints;
|
||||
/** Sloppy focus: focus follow mouse */
|
||||
Bool sloppy_focus;
|
||||
/** True if we should raise windows on focus */
|
||||
Bool sloppy_focus_raise;
|
||||
bool sloppy_focus;
|
||||
/** true if we should raise windows on focus */
|
||||
bool sloppy_focus_raise;
|
||||
/** Focus new clients */
|
||||
Bool new_get_focus;
|
||||
/** True if new clients should become master */
|
||||
Bool new_become_master;
|
||||
/** True if we need to arrange() */
|
||||
Bool need_arrange;
|
||||
bool new_get_focus;
|
||||
/** true if new clients should become master */
|
||||
bool new_become_master;
|
||||
/** true if we need to arrange() */
|
||||
bool need_arrange;
|
||||
/** Colors */
|
||||
struct
|
||||
{
|
||||
|
@ -340,8 +342,12 @@ typedef struct
|
|||
typedef struct AwesomeConf AwesomeConf;
|
||||
struct AwesomeConf
|
||||
{
|
||||
/** Display ref */
|
||||
Display *display;
|
||||
/** Connection ref */
|
||||
xcb_connection_t *connection;
|
||||
/** Event and error handlers */
|
||||
xcb_event_handlers_t *evenths;
|
||||
/** Default screen number */
|
||||
int default_screen;
|
||||
/** Logical screens */
|
||||
VirtScreen *screens;
|
||||
/** Screens info */
|
||||
|
@ -360,18 +366,18 @@ struct AwesomeConf
|
|||
/** Numlock mask */
|
||||
unsigned int numlockmask;
|
||||
/** Check for XShape extension */
|
||||
Bool have_shape;
|
||||
bool have_shape;
|
||||
/** Check for XRandR extension */
|
||||
Bool have_randr;
|
||||
bool have_randr;
|
||||
/** Cursors */
|
||||
Cursor cursor[CurLast];
|
||||
xcb_cursor_t cursor[CurLast];
|
||||
/** Clients list */
|
||||
Client *clients;
|
||||
/** Scratch client */
|
||||
struct
|
||||
{
|
||||
Client *client;
|
||||
Bool isvisible;
|
||||
bool isvisible;
|
||||
} scratch;
|
||||
/** Path to config file */
|
||||
char *configpath;
|
||||
|
|
30
tag.c
30
tag.c
|
@ -109,7 +109,7 @@ tag_client(Client *c, Tag *t)
|
|||
|
||||
client_saveprops(c);
|
||||
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
||||
globalconf.screens[c->screen].need_arrange = True;
|
||||
globalconf.screens[c->screen].need_arrange = true;
|
||||
}
|
||||
|
||||
/** Untag a client with specified tag.
|
||||
|
@ -138,19 +138,19 @@ untag_client(Client *c, Tag *t)
|
|||
* \param t the tag
|
||||
* \return true if the client is tagged with the tag, false otherwise.
|
||||
*/
|
||||
Bool
|
||||
bool
|
||||
is_client_tagged(Client *c, Tag *t)
|
||||
{
|
||||
tag_client_node_t *tc;
|
||||
|
||||
if(!c)
|
||||
return False;
|
||||
return false;
|
||||
|
||||
for(tc = globalconf.tclink; tc; tc = tc->next)
|
||||
if(tc->client == c && tc->tag == t)
|
||||
return True;
|
||||
return true;
|
||||
|
||||
return False;
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Tag the client with the currently selected (visible) tags.
|
||||
|
@ -177,7 +177,7 @@ void
|
|||
tag_client_with_rule(Client *c, Rule *r)
|
||||
{
|
||||
Tag *tag;
|
||||
Bool matched = False;
|
||||
bool matched = false;
|
||||
|
||||
if(!r) return;
|
||||
|
||||
|
@ -185,7 +185,7 @@ tag_client_with_rule(Client *c, Rule *r)
|
|||
for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
|
||||
if(tag_match_rule(tag, r))
|
||||
{
|
||||
matched = True;
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -360,7 +360,7 @@ tag_view_only(Tag *target)
|
|||
* \param view the view value
|
||||
*/
|
||||
void
|
||||
tag_view_byindex(int screen, int dindex, Bool view)
|
||||
tag_view_byindex(int screen, int dindex, bool view)
|
||||
{
|
||||
Tag *tag;
|
||||
|
||||
|
@ -394,13 +394,13 @@ tag_view_only_byindex(int screen, int dindex)
|
|||
* \param view set visible or not
|
||||
*/
|
||||
void
|
||||
tag_view(Tag *tag, Bool view)
|
||||
tag_view(Tag *tag, bool view)
|
||||
{
|
||||
tag->was_selected = tag->selected;
|
||||
tag->selected = view;
|
||||
ewmh_update_net_current_desktop(screen_virttophys(tag->screen));
|
||||
widget_invalidate_cache(tag->screen, WIDGET_CACHE_TAGS);
|
||||
globalconf.screens[tag->screen].need_arrange = True;
|
||||
globalconf.screens[tag->screen].need_arrange = true;
|
||||
}
|
||||
|
||||
/** View only this tag.
|
||||
|
@ -417,7 +417,7 @@ uicb_tag_view(int screen, char *arg)
|
|||
tag_view_only_byindex(screen, atoi(arg) - 1);
|
||||
else
|
||||
for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
|
||||
tag_view(tag, True);
|
||||
tag_view(tag, true);
|
||||
}
|
||||
|
||||
/** View the previously selected tags.
|
||||
|
@ -446,8 +446,8 @@ uicb_tag_viewnext(int screen, char *arg __attribute__ ((unused)))
|
|||
|
||||
tag = tag_list_next_cycle(&globalconf.screens[screen].tags, curtags[0]);
|
||||
|
||||
tag_view(curtags[0], False);
|
||||
tag_view(tag, True);
|
||||
tag_view(curtags[0], false);
|
||||
tag_view(tag, true);
|
||||
|
||||
p_delete(&curtags);
|
||||
}
|
||||
|
@ -464,8 +464,8 @@ uicb_tag_viewprev(int screen, char *arg __attribute__ ((unused)))
|
|||
|
||||
tag = tag_list_prev_cycle(&globalconf.screens[screen].tags, curtags[0]);
|
||||
|
||||
tag_view(curtags[0], False);
|
||||
tag_view(tag, True);
|
||||
tag_view(curtags[0], false);
|
||||
tag_view(tag, true);
|
||||
|
||||
p_delete(&curtags);
|
||||
}
|
||||
|
|
6
tag.h
6
tag.h
|
@ -28,13 +28,13 @@
|
|||
#define IS_TILED(client, screen) (client && !client->isfloating && !client->ismax && client_isvisible(client, screen))
|
||||
|
||||
Tag * tag_new(const char *, Layout *, double, int, int);
|
||||
void tag_view(Tag *, Bool);
|
||||
void tag_view_byindex(int, int, Bool);
|
||||
void tag_view(Tag *, bool);
|
||||
void tag_view_byindex(int, int, bool);
|
||||
void tag_push_to_screen(Tag *, int);
|
||||
Tag ** tags_get_current(int);
|
||||
void tag_client(Client *, Tag *);
|
||||
void untag_client(Client *, Tag *);
|
||||
Bool is_client_tagged(Client *, Tag *);
|
||||
bool is_client_tagged(Client *, Tag *);
|
||||
void tag_client_with_rule(Client *, Rule *r);
|
||||
void tag_client_with_current_selected(Client *);
|
||||
void tag_view_only_byindex(int, int);
|
||||
|
|
38
titlebar.c
38
titlebar.c
|
@ -19,6 +19,9 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_aux.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "titlebar.h"
|
||||
|
@ -54,7 +57,7 @@ titlebar_init(Client *c)
|
|||
width = c->geometry.width + 2 * c->border;
|
||||
else
|
||||
width = MIN(c->titlebar.width, c->geometry.width);
|
||||
c->titlebar.sw = simplewindow_new(globalconf.display,
|
||||
c->titlebar.sw = simplewindow_new(globalconf.connection,
|
||||
c->phys_screen, 0, 0,
|
||||
width, c->titlebar.height, 0);
|
||||
break;
|
||||
|
@ -64,14 +67,14 @@ titlebar_init(Client *c)
|
|||
width = c->geometry.height + 2 * c->border;
|
||||
else
|
||||
width = MIN(c->titlebar.width, c->geometry.height);
|
||||
c->titlebar.sw = simplewindow_new(globalconf.display,
|
||||
c->titlebar.sw = simplewindow_new(globalconf.connection,
|
||||
c->phys_screen, 0, 0,
|
||||
c->titlebar.height, width, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
XMapWindow(globalconf.display, c->titlebar.sw->window);
|
||||
xcb_map_window(globalconf.connection, c->titlebar.sw->window);
|
||||
}
|
||||
|
||||
/** Add the titlebar geometry to a geometry.
|
||||
|
@ -148,26 +151,31 @@ titlebar_geometry_remove(Titlebar *t, area_t geometry)
|
|||
void
|
||||
titlebar_draw(Client *c)
|
||||
{
|
||||
Drawable dw = 0;
|
||||
xcb_drawable_t dw = 0;
|
||||
DrawCtx *ctx;
|
||||
style_t style;
|
||||
area_t geometry;
|
||||
xcb_screen_t *s;
|
||||
|
||||
if(!c->titlebar.sw)
|
||||
return;
|
||||
|
||||
s = xcb_aux_get_screen(globalconf.connection,
|
||||
c->titlebar.sw->phys_screen);
|
||||
|
||||
switch(c->titlebar.position)
|
||||
{
|
||||
case Off:
|
||||
return;
|
||||
case Right:
|
||||
case Left:
|
||||
dw = XCreatePixmap(globalconf.display,
|
||||
RootWindow(globalconf.display, c->titlebar.sw->phys_screen),
|
||||
dw = xcb_generate_id(globalconf.connection);
|
||||
xcb_create_pixmap(globalconf.connection, s->root_depth,
|
||||
dw,
|
||||
root_window(globalconf.connection, c->titlebar.sw->phys_screen),
|
||||
c->titlebar.sw->geometry.height,
|
||||
c->titlebar.sw->geometry.width,
|
||||
DefaultDepth(globalconf.display, c->titlebar.sw->phys_screen));
|
||||
ctx = draw_context_new(globalconf.display, c->titlebar.sw->phys_screen,
|
||||
c->titlebar.sw->geometry.width);
|
||||
ctx = draw_context_new(globalconf.connection, c->titlebar.sw->phys_screen,
|
||||
c->titlebar.sw->geometry.height,
|
||||
c->titlebar.sw->geometry.width,
|
||||
dw);
|
||||
|
@ -175,7 +183,7 @@ titlebar_draw(Client *c)
|
|||
geometry.height = c->titlebar.sw->geometry.width;
|
||||
break;
|
||||
default:
|
||||
ctx = draw_context_new(globalconf.display, c->titlebar.sw->phys_screen,
|
||||
ctx = draw_context_new(globalconf.connection, c->titlebar.sw->phys_screen,
|
||||
c->titlebar.sw->geometry.width,
|
||||
c->titlebar.sw->geometry.height,
|
||||
c->titlebar.sw->drawable);
|
||||
|
@ -201,12 +209,12 @@ titlebar_draw(Client *c)
|
|||
case Left:
|
||||
draw_rotate(ctx, c->titlebar.sw->drawable, ctx->height, ctx->width,
|
||||
- M_PI_2, 0, c->titlebar.sw->geometry.height);
|
||||
XFreePixmap(globalconf.display, dw);
|
||||
xcb_free_pixmap(globalconf.connection, dw);
|
||||
break;
|
||||
case Right:
|
||||
draw_rotate(ctx, c->titlebar.sw->drawable, ctx->height, ctx->width,
|
||||
M_PI_2, c->titlebar.sw->geometry.width, 0);
|
||||
XFreePixmap(globalconf.display, dw);
|
||||
xcb_free_pixmap(globalconf.connection, dw);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -447,9 +455,9 @@ titlebar_position_set(Titlebar *t, Position p)
|
|||
return;
|
||||
|
||||
if((t->position = p))
|
||||
XMapWindow(globalconf.display, t->sw->window);
|
||||
xcb_map_window(globalconf.connection, t->sw->window);
|
||||
else
|
||||
XUnmapWindow(globalconf.display, t->sw->window);
|
||||
xcb_unmap_window(globalconf.connection, t->sw->window);
|
||||
}
|
||||
|
||||
/** Toggle the visibility of the focused window's titlebar.
|
||||
|
@ -473,7 +481,7 @@ uicb_client_toggletitlebar(int screen __attribute__ ((unused)), char *arg __attr
|
|||
if(c->isfloating || layout_get_current(screen)->arrange == layout_floating)
|
||||
titlebar_update_geometry_floating(c);
|
||||
else
|
||||
globalconf.screens[c->screen].need_arrange = True;
|
||||
globalconf.screens[c->screen].need_arrange = true;
|
||||
}
|
||||
|
||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||
|
|
11
uicb.c
11
uicb.c
|
@ -28,6 +28,9 @@
|
|||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_aux.h>
|
||||
|
||||
#include "awesome.h"
|
||||
#include "tag.h"
|
||||
#include "mouse.h"
|
||||
|
@ -69,8 +72,8 @@ uicb_exec(int screen __attribute__ ((unused)), char *cmd)
|
|||
for(c = globalconf.clients; c; c = c->next)
|
||||
client_unban(c);
|
||||
|
||||
XSync(globalconf.display, False);
|
||||
XCloseDisplay(globalconf.display);
|
||||
xcb_aux_sync(globalconf.connection);
|
||||
xcb_disconnect(globalconf.connection);
|
||||
|
||||
/* Ignore the leading spaces if any */
|
||||
while(cmd[0] && cmd[0] == ' ')
|
||||
|
@ -123,8 +126,8 @@ uicb_spawn(int screen, char *arg)
|
|||
{
|
||||
if(fork() == 0)
|
||||
{
|
||||
if(globalconf.display)
|
||||
close(ConnectionNumber(globalconf.display));
|
||||
if(globalconf.connection)
|
||||
close(xcb_get_file_descriptor(globalconf.connection));
|
||||
setsid();
|
||||
execl(shell, shell, "-c", arg, NULL);
|
||||
warn("execl '%s -c %s' failed: %s\n", shell, arg, strerror(errno));
|
||||
|
|
8
widget.c
8
widget.c
|
@ -110,12 +110,12 @@ widget_getbyname(Statusbar *sb, char *name)
|
|||
* \param ev the XButtonPressedEvent the widget received
|
||||
*/
|
||||
static void
|
||||
widget_common_button_press(Widget *widget, XButtonPressedEvent *ev)
|
||||
widget_common_button_press(Widget *widget, xcb_button_press_event_t *ev)
|
||||
{
|
||||
Button *b;
|
||||
|
||||
for(b = widget->buttons; b; b = b->next)
|
||||
if(ev->button == b->button && CLEANMASK(ev->state) == b->mod && b->func)
|
||||
if(ev->detail == b->button && CLEANMASK(ev->state) == b->mod && b->func)
|
||||
{
|
||||
b->func(widget->statusbar->screen, b->arg);
|
||||
break;
|
||||
|
@ -171,7 +171,7 @@ widget_invalidate_cache(int screen, int flags)
|
|||
statusbar = statusbar->next)
|
||||
for(widget = statusbar->widgets; widget; widget = widget->next)
|
||||
if(widget->cache.flags & flags)
|
||||
widget->cache.needs_update = True;
|
||||
widget->cache.needs_update = true;
|
||||
}
|
||||
|
||||
/** Send commands to widgets.
|
||||
|
@ -251,7 +251,7 @@ uicb_widget_tell(int screen, char *arg)
|
|||
property, widget->name);
|
||||
break;
|
||||
case WIDGET_NOERROR:
|
||||
widget->cache.needs_update = True;
|
||||
widget->cache.needs_update = true;
|
||||
break;
|
||||
case WIDGET_ERROR_CUSTOM:
|
||||
break;
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
extern AwesomeConf globalconf;
|
||||
|
||||
widget_tell_status_t
|
||||
widget_set_color_for_data(Widget *widget, XColor *color, char *command, int data_items, char ** data_title)
|
||||
widget_set_color_for_data(Widget *widget, xcolor_t *color, char *command, int data_items, char ** data_title)
|
||||
{
|
||||
char *title, *setting;
|
||||
int i;
|
||||
|
@ -35,7 +35,7 @@ widget_set_color_for_data(Widget *widget, XColor *color, char *command, int data
|
|||
for(i = 0; i < data_items; i++)
|
||||
if(!a_strcmp(title, data_title[i]))
|
||||
{
|
||||
if(draw_color_new(globalconf.display,
|
||||
if(draw_color_new(globalconf.connection,
|
||||
widget->statusbar->phys_screen,
|
||||
setting, &color[i]))
|
||||
return WIDGET_NOERROR;
|
||||
|
@ -45,24 +45,24 @@ widget_set_color_for_data(Widget *widget, XColor *color, char *command, int data
|
|||
return WIDGET_ERROR_FORMAT_SECTION;
|
||||
}
|
||||
widget_tell_status_t
|
||||
widget_set_color_pointer_for_data(Widget *widget, XColor **color, char *command, int data_items, char ** data_title)
|
||||
widget_set_color_pointer_for_data(Widget *widget, xcolor_t **color, char *command, int data_items, char ** data_title)
|
||||
{
|
||||
char *title, *setting;
|
||||
int i;
|
||||
Bool flag;
|
||||
bool flag;
|
||||
title = strtok(command, " ");
|
||||
if(!(setting = strtok(NULL, " ")))
|
||||
return WIDGET_ERROR_NOVALUE;
|
||||
for(i = 0; i < data_items; i++)
|
||||
if(!a_strcmp(title, data_title[i]))
|
||||
{
|
||||
flag = False;
|
||||
flag = false;
|
||||
if(!color[i])
|
||||
{
|
||||
flag = True; /* p_delete && restore to NULL, if draw_color_new unsuccessful */
|
||||
color[i] = p_new(XColor, 1);
|
||||
flag = true; /* p_delete && restore to NULL, if draw_color_new unsuccessful */
|
||||
color[i] = p_new(xcolor_t, 1);
|
||||
}
|
||||
if(!(draw_color_new(globalconf.display,
|
||||
if(!(draw_color_new(globalconf.connection,
|
||||
widget->statusbar->phys_screen,
|
||||
setting, color[i])))
|
||||
{
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
#define AWESOME_WIDGETS_COMMON_H
|
||||
#include "widget.h"
|
||||
|
||||
widget_tell_status_t widget_set_color_for_data(Widget *, XColor *, char *, int, char **);
|
||||
widget_tell_status_t widget_set_color_pointer_for_data(Widget *, XColor **, char *, int, char **);
|
||||
widget_tell_status_t widget_set_color_for_data(Widget *, xcolor_t *, char *, int, char **);
|
||||
widget_tell_status_t widget_set_color_pointer_for_data(Widget *, xcolor_t **, char *, int, char **);
|
||||
|
||||
#endif
|
||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||
|
|
|
@ -43,7 +43,7 @@ emptybox_draw(Widget *widget, DrawCtx *ctx, int offset,
|
|||
if(!widget->user_supplied_y)
|
||||
widget->area.y = 0;
|
||||
|
||||
draw_rectangle(ctx, widget->area, 1.0, True, d->style.bg);
|
||||
draw_rectangle(ctx, widget->area, 1.0, true, d->style.bg);
|
||||
|
||||
return widget->area.width;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ emptybox_new(Statusbar *statusbar, cfg_t *config)
|
|||
|
||||
w->data = d = p_new(Data, 1);
|
||||
|
||||
draw_style_init(globalconf.display, statusbar->phys_screen,
|
||||
draw_style_init(globalconf.connection, statusbar->phys_screen,
|
||||
cfg_getsec(config, "style"),
|
||||
&d->style,
|
||||
&globalconf.screens[statusbar->screen].styles.normal);
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "common/util.h"
|
||||
#include "common/draw.h"
|
||||
#include "common/configopts.h"
|
||||
#include "common/xutil.h"
|
||||
|
||||
extern AwesomeConf globalconf;
|
||||
|
||||
|
@ -38,8 +39,8 @@ typedef struct
|
|||
float height; /** Height of graph (0-1; 1 = height of statusbar) */
|
||||
int box_height; /** Height of the innerbox in pixels */
|
||||
int size; /** Size of lines-array (also innerbox-lenght) */
|
||||
XColor bg; /** Background color */
|
||||
XColor bordercolor; /** Border color */
|
||||
xcolor_t bg; /** Background color */
|
||||
xcolor_t bordercolor; /** Border color */
|
||||
Position grow; /** grow: Left or Right */
|
||||
|
||||
/* markers... */
|
||||
|
@ -56,24 +57,24 @@ typedef struct
|
|||
int **fillbottom; /** Data array pointer (like *lines) */
|
||||
int **fillbottom_index; /** Points to some index[i] */
|
||||
int fillbottom_total; /** Total of them */
|
||||
Bool *fillbottom_vertical_grad; /** Create a vertical color gradient */
|
||||
XColor *fillbottom_color; /** Color of them */
|
||||
XColor **fillbottom_pcolor_center; /** Color at middle of graph */
|
||||
XColor **fillbottom_pcolor_end; /** Color at end of graph */
|
||||
bool *fillbottom_vertical_grad; /** Create a vertical color gradient */
|
||||
xcolor_t *fillbottom_color; /** Color of them */
|
||||
xcolor_t **fillbottom_pcolor_center; /** Color at middle of graph */
|
||||
xcolor_t **fillbottom_pcolor_end; /** Color at end of graph */
|
||||
int **filltop; /** Data array pointer (like *lines) */
|
||||
int **filltop_index; /** Points to some index[i] */
|
||||
int filltop_total; /** Total of them */
|
||||
Bool *filltop_vertical_grad; /** Create a vertical color gradient */
|
||||
XColor *filltop_color; /** Color of them */
|
||||
XColor **filltop_pcolor_center; /** Color at center of graph */
|
||||
XColor **filltop_pcolor_end; /** Color at end of graph */
|
||||
bool *filltop_vertical_grad; /** Create a vertical color gradient */
|
||||
xcolor_t *filltop_color; /** Color of them */
|
||||
xcolor_t **filltop_pcolor_center; /** Color at center of graph */
|
||||
xcolor_t **filltop_pcolor_end; /** Color at end of graph */
|
||||
int **drawline; /** Data array pointer (like *lines) */
|
||||
int **drawline_index; /** Points to some index[i] */
|
||||
int drawline_total; /** Total of them */
|
||||
Bool *drawline_vertical_grad; /** Create a vertical color gradient */
|
||||
XColor *drawline_color; /** Color of them */
|
||||
XColor **drawline_pcolor_center; /** Color at middle of graph */
|
||||
XColor **drawline_pcolor_end; /** Color at end of graph */
|
||||
bool *drawline_vertical_grad; /** Create a vertical color gradient */
|
||||
xcolor_t *drawline_color; /** Color of them */
|
||||
xcolor_t **drawline_pcolor_center; /** Color at middle of graph */
|
||||
xcolor_t **drawline_pcolor_end; /** Color at end of graph */
|
||||
|
||||
int *draw_from; /** Preparation/tmp array for draw_graph(); */
|
||||
int *draw_to; /** Preparation/tmp array for draw_graph(); */
|
||||
|
@ -111,7 +112,7 @@ graph_draw(Widget *widget, DrawCtx *ctx, int offset,
|
|||
rectangle.y = margin_top + 1;
|
||||
rectangle.width = d->size;
|
||||
rectangle.height = d->box_height;
|
||||
draw_rectangle(ctx, rectangle, 1.0, True, d->bg);
|
||||
draw_rectangle(ctx, rectangle, 1.0, true, d->bg);
|
||||
|
||||
/* for graph drawing */
|
||||
rectangle.y = margin_top + d->box_height + 1; /* bottom left corner as starting point */
|
||||
|
@ -267,7 +268,7 @@ graph_draw(Widget *widget, DrawCtx *ctx, int offset,
|
|||
rectangle.y = margin_top;
|
||||
rectangle.width = d->size + 2;
|
||||
rectangle.height = d->box_height + 2;
|
||||
draw_rectangle(ctx, rectangle, 1.0, False, d->bordercolor);
|
||||
draw_rectangle(ctx, rectangle, 1.0, false, d->bordercolor);
|
||||
|
||||
widget->area.width = d->width;
|
||||
widget->area.height = widget->statusbar->height;
|
||||
|
@ -349,14 +350,14 @@ graph_tell(Widget *widget, char *property, char *command)
|
|||
d->height = atof(command);
|
||||
else if(!a_strcmp(property, "bg"))
|
||||
{
|
||||
if(!draw_color_new(globalconf.display,
|
||||
if(!draw_color_new(globalconf.connection,
|
||||
widget->statusbar->phys_screen,
|
||||
command, &d->bg))
|
||||
return WIDGET_ERROR_FORMAT_COLOR;
|
||||
}
|
||||
else if(!a_strcmp(property, "bordercolor"))
|
||||
{
|
||||
if(!draw_color_new(globalconf.display,
|
||||
if(!draw_color_new(globalconf.connection,
|
||||
widget->statusbar->phys_screen,
|
||||
command, &d->bordercolor))
|
||||
return WIDGET_ERROR_FORMAT_COLOR;
|
||||
|
@ -387,9 +388,9 @@ graph_new(Statusbar *statusbar, cfg_t *config)
|
|||
char *color;
|
||||
int i;
|
||||
char *type;
|
||||
XColor tmp_color = { 0, 0, 0, 0, 0, 0 };
|
||||
XColor *ptmp_color_center;
|
||||
XColor *ptmp_color_end;
|
||||
xcolor_t tmp_color = { 0, 0, 0, 0 };
|
||||
xcolor_t *ptmp_color_center;
|
||||
xcolor_t *ptmp_color_end;
|
||||
|
||||
w = p_new(Widget, 1);
|
||||
widget_common_new(w, statusbar, config);
|
||||
|
@ -431,18 +432,18 @@ graph_new(Statusbar *statusbar, cfg_t *config)
|
|||
d->values = p_new(float *, d->data_items);
|
||||
d->lines = p_new(int *, d->data_items);
|
||||
|
||||
d->filltop_color = p_new(XColor, d->data_items);
|
||||
d->filltop_pcolor_center = p_new(XColor *, d->data_items);
|
||||
d->filltop_pcolor_end = p_new(XColor *, d->data_items);
|
||||
d->filltop_vertical_grad = p_new(Bool, d->data_items);
|
||||
d->fillbottom_color = p_new(XColor, d->data_items);
|
||||
d->fillbottom_pcolor_center = p_new(XColor *, d->data_items);
|
||||
d->fillbottom_pcolor_end = p_new(XColor *, d->data_items);
|
||||
d->fillbottom_vertical_grad = p_new(Bool, d->data_items);
|
||||
d->drawline_color = p_new(XColor, d->data_items);
|
||||
d->drawline_pcolor_center = p_new(XColor *, d->data_items);
|
||||
d->drawline_pcolor_end = p_new(XColor *, d->data_items);
|
||||
d->drawline_vertical_grad = p_new(Bool, d->data_items);
|
||||
d->filltop_color = p_new(xcolor_t, d->data_items);
|
||||
d->filltop_pcolor_center = p_new(xcolor_t *, d->data_items);
|
||||
d->filltop_pcolor_end = p_new(xcolor_t *, d->data_items);
|
||||
d->filltop_vertical_grad = p_new(bool, d->data_items);
|
||||
d->fillbottom_color = p_new(xcolor_t, d->data_items);
|
||||
d->fillbottom_pcolor_center = p_new(xcolor_t *, d->data_items);
|
||||
d->fillbottom_pcolor_end = p_new(xcolor_t *, d->data_items);
|
||||
d->fillbottom_vertical_grad = p_new(bool, d->data_items);
|
||||
d->drawline_color = p_new(xcolor_t, d->data_items);
|
||||
d->drawline_pcolor_center = p_new(xcolor_t *, d->data_items);
|
||||
d->drawline_pcolor_end = p_new(xcolor_t *, d->data_items);
|
||||
d->drawline_vertical_grad = p_new(bool, d->data_items);
|
||||
|
||||
d->max_index = p_new(int, d->data_items);
|
||||
d->index = p_new(int, d->data_items);
|
||||
|
@ -459,20 +460,20 @@ graph_new(Statusbar *statusbar, cfg_t *config)
|
|||
d->data_title[i] = a_strdup(cfg_title(cfg));
|
||||
|
||||
if((color = cfg_getstr(cfg, "fg")))
|
||||
draw_color_new(globalconf.display, statusbar->phys_screen, color, &tmp_color);
|
||||
draw_color_new(globalconf.connection, statusbar->phys_screen, color, &tmp_color);
|
||||
else
|
||||
tmp_color = globalconf.screens[statusbar->screen].styles.normal.fg;
|
||||
|
||||
if((color = cfg_getstr(cfg, "fg_center")))
|
||||
{
|
||||
ptmp_color_center = p_new(XColor, 1);
|
||||
draw_color_new(globalconf.display, statusbar->phys_screen, color, ptmp_color_center);
|
||||
ptmp_color_center = p_new(xcolor_t, 1);
|
||||
draw_color_new(globalconf.connection, statusbar->phys_screen, color, ptmp_color_center);
|
||||
}
|
||||
|
||||
if((color = cfg_getstr(cfg, "fg_end")))
|
||||
{
|
||||
ptmp_color_end = p_new(XColor, 1);
|
||||
draw_color_new(globalconf.display, statusbar->phys_screen, color, ptmp_color_end);
|
||||
ptmp_color_end = p_new(xcolor_t, 1);
|
||||
draw_color_new(globalconf.connection, statusbar->phys_screen, color, ptmp_color_end);
|
||||
}
|
||||
|
||||
if (cfg_getbool(cfg, "scale"))
|
||||
|
@ -520,12 +521,12 @@ graph_new(Statusbar *statusbar, cfg_t *config)
|
|||
}
|
||||
|
||||
if((color = cfg_getstr(config, "bg")))
|
||||
draw_color_new(globalconf.display, statusbar->phys_screen, color, &d->bg);
|
||||
draw_color_new(globalconf.connection, statusbar->phys_screen, color, &d->bg);
|
||||
else
|
||||
d->bg = globalconf.screens[statusbar->screen].styles.normal.bg;
|
||||
|
||||
if((color = cfg_getstr(config, "bordercolor")))
|
||||
draw_color_new(globalconf.display, statusbar->phys_screen, color, &d->bordercolor);
|
||||
draw_color_new(globalconf.connection, statusbar->phys_screen, color, &d->bordercolor);
|
||||
else
|
||||
d->bordercolor = tmp_color;
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ extern AwesomeConf globalconf;
|
|||
typedef struct
|
||||
{
|
||||
char *image;
|
||||
Bool resize;
|
||||
bool resize;
|
||||
} Data;
|
||||
|
||||
static int
|
||||
|
@ -67,7 +67,7 @@ iconbox_draw(Widget *widget, DrawCtx *ctx, int offset,
|
|||
static widget_tell_status_t
|
||||
iconbox_tell(Widget *widget, char *property, char *command)
|
||||
{
|
||||
Bool b;
|
||||
bool b;
|
||||
Data *d = widget->data;
|
||||
|
||||
if(command == NULL)
|
||||
|
|
|
@ -50,28 +50,28 @@ typedef struct
|
|||
/** total number of ticks */
|
||||
int ticks_count;
|
||||
/** reverse drawing */
|
||||
Bool *reverse;
|
||||
bool *reverse;
|
||||
/** 90 Degree's turned */
|
||||
Bool vertical;
|
||||
bool vertical;
|
||||
/** Number of data_items (bars) */
|
||||
int data_items;
|
||||
/** Height 0-1, where 1 is height of statusbar */
|
||||
float height;
|
||||
/** Foreground color */
|
||||
XColor *fg;
|
||||
xcolor_t *fg;
|
||||
/** Foreground color of turned-off ticks */
|
||||
XColor *fg_off;
|
||||
xcolor_t *fg_off;
|
||||
/** Foreground color when bar is half-full */
|
||||
XColor **pfg_center;
|
||||
xcolor_t **pfg_center;
|
||||
/** Foreground color when bar is full */
|
||||
XColor **pfg_end;
|
||||
xcolor_t **pfg_end;
|
||||
/** Background color */
|
||||
XColor *bg;
|
||||
xcolor_t *bg;
|
||||
/** Border color */
|
||||
XColor *bordercolor;
|
||||
xcolor_t *bordercolor;
|
||||
} Data;
|
||||
|
||||
static Bool
|
||||
static bool
|
||||
check_settings(Data *d, int status_height)
|
||||
{
|
||||
int tmp, h_total;
|
||||
|
@ -85,14 +85,14 @@ check_settings(Data *d, int status_height)
|
|||
|| (!d->ticks_count && tmp < 0))
|
||||
{
|
||||
warn("progressbar's 'width' is too small for the given configuration options\n");
|
||||
return False;
|
||||
return false;
|
||||
}
|
||||
tmp = h_total - d->data_items * (2 * (d->border_width + d->border_padding) + 1)
|
||||
- (d->data_items - 1) * d->gap;
|
||||
if(tmp < 0)
|
||||
{
|
||||
warn("progressbar's 'height' is too small for the given configuration options\n");
|
||||
return False;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else /* vertical / standing up */
|
||||
|
@ -102,17 +102,17 @@ check_settings(Data *d, int status_height)
|
|||
|| (!d->ticks_count && tmp < 0))
|
||||
{
|
||||
warn("progressbar's 'height' is too small for the given configuration options\n");
|
||||
return False;
|
||||
return false;
|
||||
}
|
||||
tmp = d->width - d->data_items * (2 * (d->border_width + d->border_padding) + 1)
|
||||
- (d->data_items - 1) * d->gap;
|
||||
if(tmp < 0)
|
||||
{
|
||||
warn("progressbar's 'width' is too small for the given configuration options\n");
|
||||
return False;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return True;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -208,8 +208,8 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset,
|
|||
rectangle.height = pb_height + 2 * (d->border_padding + d->border_width);
|
||||
|
||||
if(d->border_padding)
|
||||
draw_rectangle(ctx, rectangle, 1.0, True, d->bg[i]);
|
||||
draw_rectangle(ctx, rectangle, d->border_width, False, d->bordercolor[i]);
|
||||
draw_rectangle(ctx, rectangle, 1.0, true, d->bg[i]);
|
||||
draw_rectangle(ctx, rectangle, d->border_width, false, d->bordercolor[i]);
|
||||
}
|
||||
|
||||
/* new value/progress in px + pattern setup */
|
||||
|
@ -241,10 +241,10 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset,
|
|||
|
||||
/* fg color */
|
||||
if(!d->reverse[i])
|
||||
draw_rectangle_gradient(ctx, rectangle, 1.0, True, pattern_rect,
|
||||
draw_rectangle_gradient(ctx, rectangle, 1.0, true, pattern_rect,
|
||||
&(d->fg[i]), d->pfg_center[i], d->pfg_end[i]);
|
||||
else /*REV: bg */
|
||||
draw_rectangle(ctx, rectangle, 1.0, True, d->fg_off[i]);
|
||||
draw_rectangle(ctx, rectangle, 1.0, true, d->fg_off[i]);
|
||||
}
|
||||
|
||||
/* top part */
|
||||
|
@ -257,9 +257,9 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset,
|
|||
|
||||
/* bg color */
|
||||
if(!d->reverse[i])
|
||||
draw_rectangle(ctx, rectangle, 1.0, True, d->fg_off[i]);
|
||||
draw_rectangle(ctx, rectangle, 1.0, true, d->fg_off[i]);
|
||||
else /* REV: fg */
|
||||
draw_rectangle_gradient(ctx, rectangle, 1.0, True, pattern_rect,
|
||||
draw_rectangle_gradient(ctx, rectangle, 1.0, true, pattern_rect,
|
||||
&(d->fg[i]), d->pfg_center[i], d->pfg_end[i]);
|
||||
}
|
||||
/* draw gaps TODO: improve e.g all in one */
|
||||
|
@ -272,7 +272,7 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset,
|
|||
pb_y + pb_height - d->ticks_gap >= rectangle.y;
|
||||
rectangle.y += unit)
|
||||
{
|
||||
draw_rectangle(ctx, rectangle, 1.0, True, d->bg[i]);
|
||||
draw_rectangle(ctx, rectangle, 1.0, true, d->bg[i]);
|
||||
}
|
||||
}
|
||||
pb_offset += pb_width + d->gap + 2 * (d->border_width + d->border_padding);
|
||||
|
@ -309,8 +309,8 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset,
|
|||
rectangle.height = pb_height + 2 * (d->border_padding + d->border_width);
|
||||
|
||||
if(d->border_padding)
|
||||
draw_rectangle(ctx, rectangle, 1.0, True, d->bg[i]);
|
||||
draw_rectangle(ctx, rectangle, d->border_width, False, d->bordercolor[i]);
|
||||
draw_rectangle(ctx, rectangle, 1.0, true, d->bg[i]);
|
||||
draw_rectangle(ctx, rectangle, d->border_width, false, d->bordercolor[i]);
|
||||
}
|
||||
/* new value/progress in px + pattern setup */
|
||||
if(!d->reverse[i])
|
||||
|
@ -341,10 +341,10 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset,
|
|||
|
||||
/* fg color */
|
||||
if(!d->reverse[i])
|
||||
draw_rectangle_gradient(ctx, rectangle, 1.0, True, pattern_rect,
|
||||
draw_rectangle_gradient(ctx, rectangle, 1.0, true, pattern_rect,
|
||||
&(d->fg[i]), d->pfg_center[i], d->pfg_end[i]);
|
||||
else /* reverse: bg */
|
||||
draw_rectangle(ctx, rectangle, 1.0, True, d->fg_off[i]);
|
||||
draw_rectangle(ctx, rectangle, 1.0, true, d->fg_off[i]);
|
||||
}
|
||||
|
||||
/* right part */
|
||||
|
@ -357,9 +357,9 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset,
|
|||
|
||||
/* bg color */
|
||||
if(!d->reverse[i])
|
||||
draw_rectangle(ctx, rectangle, 1.0, True, d->fg_off[i]);
|
||||
draw_rectangle(ctx, rectangle, 1.0, true, d->fg_off[i]);
|
||||
else /* reverse: fg */
|
||||
draw_rectangle_gradient(ctx, rectangle, 1.0, True, pattern_rect,
|
||||
draw_rectangle_gradient(ctx, rectangle, 1.0, true, pattern_rect,
|
||||
&(d->fg[i]), d->pfg_center[i], d->pfg_end[i]);
|
||||
}
|
||||
/* draw gaps TODO: improve e.g all in one */
|
||||
|
@ -371,7 +371,7 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset,
|
|||
for(rectangle.x = pb_x + (unit - d->ticks_gap);
|
||||
pb_x + pb_width - d->ticks_gap >= rectangle.x;
|
||||
rectangle.x += unit)
|
||||
draw_rectangle(ctx, rectangle, 1.0, True, d->bg[i]);
|
||||
draw_rectangle(ctx, rectangle, 1.0, true, d->bg[i]);
|
||||
}
|
||||
|
||||
pb_offset += pb_height + d->gap + 2 * (d->border_width + d->border_padding);
|
||||
|
@ -475,7 +475,7 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
|
|||
d->border_width = cfg_getint(config, "border_width");
|
||||
|
||||
if(!(d->vertical = cfg_getbool(config, "vertical")))
|
||||
d->vertical = False;
|
||||
d->vertical = false;
|
||||
|
||||
d->gap = cfg_getint(config, "gap");
|
||||
|
||||
|
@ -493,14 +493,14 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
|
|||
return w;
|
||||
}
|
||||
|
||||
d->fg = p_new(XColor, d->data_items);
|
||||
d->pfg_end = p_new(XColor *, d->data_items);
|
||||
d->pfg_center = p_new(XColor *, d->data_items);
|
||||
d->fg_off = p_new(XColor, d->data_items);
|
||||
d->bg = p_new(XColor, d->data_items);
|
||||
d->bordercolor = p_new(XColor, d->data_items);
|
||||
d->fg = p_new(xcolor_t, d->data_items);
|
||||
d->pfg_end = p_new(xcolor_t *, d->data_items);
|
||||
d->pfg_center = p_new(xcolor_t *, d->data_items);
|
||||
d->fg_off = p_new(xcolor_t, d->data_items);
|
||||
d->bg = p_new(xcolor_t, d->data_items);
|
||||
d->bordercolor = p_new(xcolor_t, d->data_items);
|
||||
d->percent = p_new(int, d->data_items);
|
||||
d->reverse = p_new(Bool, d->data_items);
|
||||
d->reverse = p_new(bool, d->data_items);
|
||||
d->data_title = p_new(char *, d->data_items);
|
||||
|
||||
for(i = 0; i < d->data_items; i++)
|
||||
|
@ -510,37 +510,37 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
|
|||
d->data_title[i] = a_strdup(cfg_title(cfg));
|
||||
|
||||
if(!(d->reverse[i] = cfg_getbool(cfg, "reverse")))
|
||||
d->reverse[i] = False;
|
||||
d->reverse[i] = false;
|
||||
|
||||
if((color = cfg_getstr(cfg, "fg")))
|
||||
draw_color_new(globalconf.display, statusbar->phys_screen, color, &d->fg[i]);
|
||||
draw_color_new(globalconf.connection, statusbar->phys_screen, color, &d->fg[i]);
|
||||
else
|
||||
d->fg[i] = globalconf.screens[statusbar->screen].styles.normal.fg;
|
||||
|
||||
if((color = cfg_getstr(cfg, "fg_center")))
|
||||
{
|
||||
d->pfg_center[i] = p_new(XColor, 1);
|
||||
draw_color_new(globalconf.display, statusbar->phys_screen, color, d->pfg_center[i]);
|
||||
d->pfg_center[i] = p_new(xcolor_t, 1);
|
||||
draw_color_new(globalconf.connection, statusbar->phys_screen, color, d->pfg_center[i]);
|
||||
}
|
||||
|
||||
if((color = cfg_getstr(cfg, "fg_end")))
|
||||
{
|
||||
d->pfg_end[i] = p_new(XColor, 1);
|
||||
draw_color_new(globalconf.display, statusbar->phys_screen, color, d->pfg_end[i]);
|
||||
d->pfg_end[i] = p_new(xcolor_t, 1);
|
||||
draw_color_new(globalconf.connection, statusbar->phys_screen, color, d->pfg_end[i]);
|
||||
}
|
||||
|
||||
if((color = cfg_getstr(cfg, "fg_off")))
|
||||
draw_color_new(globalconf.display, statusbar->phys_screen, color, &d->fg_off[i]);
|
||||
draw_color_new(globalconf.connection, statusbar->phys_screen, color, &d->fg_off[i]);
|
||||
else
|
||||
d->fg_off[i] = globalconf.screens[statusbar->screen].styles.normal.bg;
|
||||
|
||||
if((color = cfg_getstr(cfg, "bg")))
|
||||
draw_color_new(globalconf.display, statusbar->phys_screen, color, &d->bg[i]);
|
||||
draw_color_new(globalconf.connection, statusbar->phys_screen, color, &d->bg[i]);
|
||||
else
|
||||
d->bg[i] = globalconf.screens[statusbar->screen].styles.normal.bg;
|
||||
|
||||
if((color = cfg_getstr(cfg, "bordercolor")))
|
||||
draw_color_new(globalconf.display, statusbar->phys_screen, color, &d->bordercolor[i]);
|
||||
draw_color_new(globalconf.connection, statusbar->phys_screen, color, &d->bordercolor[i]);
|
||||
else
|
||||
d->bordercolor[i] = d->fg[i];
|
||||
}
|
||||
|
|
|
@ -33,30 +33,30 @@ extern AwesomeConf globalconf;
|
|||
* screen
|
||||
* \param screen screen number
|
||||
* \param t tag
|
||||
* \return True or False
|
||||
* \return true or false
|
||||
*/
|
||||
static Bool
|
||||
static bool
|
||||
isoccupied(Tag *t)
|
||||
{
|
||||
Client *c;
|
||||
|
||||
for(c = globalconf.clients; c; c = c->next)
|
||||
if(is_client_tagged(c, t) && !c->skip && c != globalconf.scratch.client)
|
||||
return True;
|
||||
return true;
|
||||
|
||||
return False;
|
||||
return false;
|
||||
}
|
||||
|
||||
static Bool
|
||||
static bool
|
||||
isurgent(Tag *t)
|
||||
{
|
||||
Client *c;
|
||||
|
||||
for(c = globalconf.clients; c; c = c->next)
|
||||
if(is_client_tagged(c, t) && c->isurgent)
|
||||
return True;
|
||||
return true;
|
||||
|
||||
return False;
|
||||
return false;
|
||||
}
|
||||
|
||||
static style_t
|
||||
|
@ -90,7 +90,8 @@ taglist_draw(Widget *widget,
|
|||
for(tag = vscreen.tags; tag; tag = tag->next)
|
||||
{
|
||||
style = tag->selected ? vscreen.styles.focus : vscreen.styles.normal;
|
||||
widget->area.width += draw_textwidth(ctx->display, style.font, tag->name)
|
||||
widget->area.width += draw_textwidth(ctx->connection, ctx->default_screen,
|
||||
style.font, tag->name)
|
||||
+ style.font->height;
|
||||
}
|
||||
|
||||
|
@ -107,7 +108,8 @@ taglist_draw(Widget *widget,
|
|||
for(tag = vscreen.tags; tag; tag = tag->next)
|
||||
{
|
||||
style = taglist_style_get(vscreen, tag);
|
||||
w = draw_textwidth(ctx->display, style.font, tag->name) + style.font->height;
|
||||
w = draw_textwidth(ctx->connection, ctx->default_screen,
|
||||
style.font, tag->name) + style.font->height;
|
||||
area.x = widget->area.x + widget->area.width;
|
||||
area.y = widget->area.y;
|
||||
area.width = w;
|
||||
|
@ -135,7 +137,7 @@ taglist_draw(Widget *widget,
|
|||
}
|
||||
|
||||
static void
|
||||
taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
|
||||
taglist_button_press(Widget *widget, xcb_button_press_event_t *ev)
|
||||
{
|
||||
VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
|
||||
Button *b;
|
||||
|
@ -145,7 +147,7 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
|
|||
style_t style;
|
||||
|
||||
for(b = widget->buttons; b; b = b->next)
|
||||
if(ev->button == b->button && CLEANMASK(ev->state) == b->mod && b->func)
|
||||
if(ev->detail == b->button && CLEANMASK(ev->state) == b->mod && b->func)
|
||||
switch(widget->statusbar->position)
|
||||
{
|
||||
case Top:
|
||||
|
@ -153,10 +155,11 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
|
|||
for(tag = vscreen.tags; tag; tag = tag->next, i++)
|
||||
{
|
||||
style = taglist_style_get(vscreen, tag);
|
||||
width = draw_textwidth(globalconf.display, style.font, tag->name)
|
||||
width = draw_textwidth(globalconf.connection, globalconf.default_screen,
|
||||
style.font, tag->name)
|
||||
+ style.font->height;
|
||||
if(ev->x >= widget->area.x + prev_width
|
||||
&& ev->x < widget->area.x + prev_width + width)
|
||||
if(ev->event_x >= widget->area.x + prev_width
|
||||
&& ev->event_x < widget->area.x + prev_width + width)
|
||||
{
|
||||
snprintf(buf, sizeof(buf), "%d", i);
|
||||
b->func(widget->statusbar->screen, buf);
|
||||
|
@ -169,9 +172,10 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
|
|||
for(tag = vscreen.tags; tag; tag = tag->next, i++)
|
||||
{
|
||||
style = taglist_style_get(vscreen, tag);
|
||||
width = draw_textwidth(globalconf.display, style.font, tag->name) + style.font->height;
|
||||
if(ev->y >= widget->area.x + prev_width
|
||||
&& ev->y < widget->area.x + prev_width + width)
|
||||
width = draw_textwidth(globalconf.connection, globalconf.default_screen,
|
||||
style.font, tag->name) + style.font->height;
|
||||
if(ev->event_y >= widget->area.x + prev_width
|
||||
&& ev->event_y < widget->area.x + prev_width + width)
|
||||
{
|
||||
snprintf(buf, sizeof(buf), "%d", i);
|
||||
b->func(widget->statusbar->screen, buf);
|
||||
|
@ -184,9 +188,10 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
|
|||
for(tag = vscreen.tags; tag; tag = tag->next, i++)
|
||||
{
|
||||
style = taglist_style_get(vscreen, tag);
|
||||
width = draw_textwidth(globalconf.display, style.font, tag->name) + style.font->height;
|
||||
if(widget->statusbar->width - ev->y >= widget->area.x + prev_width
|
||||
&& widget->statusbar->width - ev->y < widget->area.x + prev_width + width)
|
||||
width = draw_textwidth(globalconf.connection, globalconf.default_screen,
|
||||
style.font, tag->name) + style.font->height;
|
||||
if(widget->statusbar->width - ev->event_y >= widget->area.x + prev_width
|
||||
&& widget->statusbar->width - ev->event_y < widget->area.x + prev_width + width)
|
||||
{
|
||||
snprintf(buf, sizeof(buf), "%d", i);
|
||||
b->func(widget->statusbar->screen, buf);
|
||||
|
|
|
@ -42,7 +42,7 @@ typedef enum
|
|||
typedef struct
|
||||
{
|
||||
ShowClient show;
|
||||
Bool show_icons;
|
||||
bool show_icons;
|
||||
Alignment align;
|
||||
struct
|
||||
{
|
||||
|
@ -52,11 +52,11 @@ typedef struct
|
|||
} styles;
|
||||
} Data;
|
||||
|
||||
static inline Bool
|
||||
static inline bool
|
||||
tasklist_isvisible(Client *c, int screen, ShowClient show)
|
||||
{
|
||||
if(c->skip || c->skiptb)
|
||||
return False;
|
||||
return false;
|
||||
|
||||
switch(show)
|
||||
{
|
||||
|
@ -67,7 +67,7 @@ tasklist_isvisible(Client *c, int screen, ShowClient show)
|
|||
case ShowFocus:
|
||||
return (c == focus_get_current_client(screen));
|
||||
}
|
||||
return False;
|
||||
return false;
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -124,7 +124,7 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
|
|||
area.height = widget->statusbar->height;
|
||||
area.width = box_width;
|
||||
|
||||
draw_rectangle(ctx, area, 1.0, True, style.bg);
|
||||
draw_rectangle(ctx, area, 1.0, true, style.bg);
|
||||
|
||||
if((r = rule_matching_client(c)) && r->icon)
|
||||
{
|
||||
|
@ -190,7 +190,7 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
|
|||
}
|
||||
|
||||
static void
|
||||
tasklist_button_press(Widget *widget, XButtonPressedEvent *ev)
|
||||
tasklist_button_press(Widget *widget, xcb_button_press_event_t *ev)
|
||||
{
|
||||
Button *b;
|
||||
Client *c;
|
||||
|
@ -199,7 +199,7 @@ tasklist_button_press(Widget *widget, XButtonPressedEvent *ev)
|
|||
int n = 0, box_width = 0, i, ci = 0;
|
||||
|
||||
/* button1 give focus */
|
||||
if(ev->button == Button1 && CLEANMASK(ev->state) == NoSymbol)
|
||||
if(ev->detail == XCB_BUTTON_INDEX_1 && CLEANMASK(ev->state) == XCB_NO_SYMBOL)
|
||||
{
|
||||
for(c = globalconf.clients; c; c = c->next)
|
||||
if(tasklist_isvisible(c, widget->statusbar->screen, d->show))
|
||||
|
@ -210,19 +210,19 @@ tasklist_button_press(Widget *widget, XButtonPressedEvent *ev)
|
|||
|
||||
box_width = widget->area.width / n;
|
||||
|
||||
if(ev->button == Button1 && CLEANMASK(ev->state) == NoSymbol)
|
||||
if(ev->detail == XCB_BUTTON_INDEX_1 && CLEANMASK(ev->state) == XCB_NO_SYMBOL)
|
||||
{
|
||||
switch(widget->statusbar->position)
|
||||
{
|
||||
case Top:
|
||||
case Bottom:
|
||||
ci = (ev->x - widget->area.x) / box_width;
|
||||
ci = (ev->event_x - widget->area.x) / box_width;
|
||||
break;
|
||||
case Right:
|
||||
ci = (ev->y - widget->area.x) / box_width;
|
||||
ci = (ev->event_y - widget->area.x) / box_width;
|
||||
break;
|
||||
default:
|
||||
ci = ((widget->statusbar->width - ev->y) - widget->area.x) / box_width;
|
||||
ci = ((widget->statusbar->width - ev->event_y) - widget->area.x) / box_width;
|
||||
break;
|
||||
}
|
||||
/* found first visible client */
|
||||
|
@ -242,7 +242,7 @@ tasklist_button_press(Widget *widget, XButtonPressedEvent *ev)
|
|||
for(i = 0, tag = globalconf.screens[c->screen].tags; tag; tag = tag->next, i++)
|
||||
if(is_client_tagged(c, tag))
|
||||
tag_view_only_byindex(c->screen, i);
|
||||
client_focus(c, widget->statusbar->screen, True);
|
||||
client_focus(c, widget->statusbar->screen, true);
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -250,7 +250,7 @@ tasklist_button_press(Widget *widget, XButtonPressedEvent *ev)
|
|||
}
|
||||
|
||||
for(b = widget->buttons; b; b = b->next)
|
||||
if(ev->button == b->button && CLEANMASK(ev->state) == b->mod && b->func)
|
||||
if(ev->detail == b->button && CLEANMASK(ev->state) == b->mod && b->func)
|
||||
{
|
||||
b->func(widget->statusbar->screen, b->arg);
|
||||
return;
|
||||
|
@ -274,17 +274,17 @@ tasklist_new(Statusbar *statusbar, cfg_t *config)
|
|||
|
||||
cfg_styles = cfg_getsec(config, "styles");
|
||||
|
||||
draw_style_init(globalconf.display, statusbar->phys_screen,
|
||||
draw_style_init(globalconf.connection, statusbar->phys_screen,
|
||||
cfg_getsec(cfg_styles, "normal"),
|
||||
&d->styles.normal,
|
||||
&globalconf.screens[statusbar->screen].styles.normal);
|
||||
|
||||
draw_style_init(globalconf.display, statusbar->phys_screen,
|
||||
draw_style_init(globalconf.connection, statusbar->phys_screen,
|
||||
cfg_getsec(cfg_styles, "focus"),
|
||||
&d->styles.focus,
|
||||
&globalconf.screens[statusbar->screen].styles.focus);
|
||||
|
||||
draw_style_init(globalconf.display, statusbar->phys_screen,
|
||||
draw_style_init(globalconf.connection, statusbar->phys_screen,
|
||||
cfg_getsec(cfg_styles, "urgent"),
|
||||
&d->styles.urgent,
|
||||
&globalconf.screens[statusbar->screen].styles.urgent);
|
||||
|
|
|
@ -44,7 +44,8 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
|
|||
else if(widget->alignment == AlignFlex)
|
||||
widget->area.width = widget->statusbar->width - used;
|
||||
else
|
||||
widget->area.width = MIN(draw_textwidth(ctx->display, d->style.font, d->text),
|
||||
widget->area.width = MIN(draw_textwidth(ctx->connection, ctx->default_screen,
|
||||
d->style.font, d->text),
|
||||
widget->statusbar->width - used);
|
||||
|
||||
widget->area.height = widget->statusbar->height;
|
||||
|
@ -75,18 +76,18 @@ textbox_tell(Widget *widget, char *property, char *command)
|
|||
d->text = a_strdup(command);
|
||||
}
|
||||
else if(!a_strcmp(property, "fg"))
|
||||
if(draw_color_new(globalconf.display, widget->statusbar->screen, command, &d->style.fg))
|
||||
if(draw_color_new(globalconf.connection, widget->statusbar->screen, command, &d->style.fg))
|
||||
return WIDGET_NOERROR;
|
||||
else
|
||||
return WIDGET_ERROR_FORMAT_COLOR;
|
||||
else if(!a_strcmp(property, "bg"))
|
||||
if(draw_color_new(globalconf.display, widget->statusbar->screen, command, &d->style.bg))
|
||||
if(draw_color_new(globalconf.connection, widget->statusbar->screen, command, &d->style.bg))
|
||||
return WIDGET_NOERROR;
|
||||
else
|
||||
return WIDGET_ERROR_FORMAT_COLOR;
|
||||
else if(!a_strcmp(property, "font"))
|
||||
{
|
||||
if((newfont = draw_font_new(globalconf.display, command)))
|
||||
if((newfont = draw_font_new(globalconf.connection, globalconf.default_screen, command)))
|
||||
{
|
||||
if(d->style.font != globalconf.screens[widget->statusbar->screen].styles.normal.font)
|
||||
draw_font_delete(&d->style.font);
|
||||
|
@ -119,7 +120,7 @@ textbox_new(Statusbar *statusbar, cfg_t *config)
|
|||
|
||||
w->data = d = p_new(Data, 1);
|
||||
|
||||
draw_style_init(globalconf.display, statusbar->phys_screen,
|
||||
draw_style_init(globalconf.connection, statusbar->phys_screen,
|
||||
cfg_getsec(config, "style"),
|
||||
&d->style,
|
||||
&globalconf.screens[statusbar->screen].styles.normal);
|
||||
|
|
211
window.c
211
window.c
|
@ -19,8 +19,10 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/extensions/shape.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_atom.h>
|
||||
#include <xcb/shape.h>
|
||||
#include <xcb/xcb_keysyms.h>
|
||||
|
||||
#include "structs.h"
|
||||
#include "window.h"
|
||||
|
@ -28,21 +30,22 @@
|
|||
extern AwesomeConf globalconf;
|
||||
|
||||
/** Mask shorthands */
|
||||
#define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
|
||||
#define BUTTONMASK (XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE)
|
||||
|
||||
/** Set client WM_STATE property
|
||||
* \param win Window
|
||||
* \param state state
|
||||
* \return XChangeProperty result
|
||||
*/
|
||||
int
|
||||
window_setstate(Window win, long state)
|
||||
void
|
||||
window_setstate(xcb_window_t win, long state)
|
||||
{
|
||||
long data[] = { state, None };
|
||||
long data[] = { state, XCB_NONE };
|
||||
|
||||
return XChangeProperty(globalconf.display, win, XInternAtom(globalconf.display, "WM_STATE", False),
|
||||
XInternAtom(globalconf.display, "WM_STATE", False), 32,
|
||||
PropModeReplace, (unsigned char *) data, 2);
|
||||
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, win,
|
||||
x_intern_atom(globalconf.connection, "WM_STATE"),
|
||||
x_intern_atom(globalconf.connection, "WM_STATE"), 32,
|
||||
2, data);
|
||||
}
|
||||
|
||||
/** Get a window state (WM_STATE)
|
||||
|
@ -50,20 +53,27 @@ window_setstate(Window win, long state)
|
|||
* \return state
|
||||
*/
|
||||
long
|
||||
window_getstate(Window w)
|
||||
window_getstate(xcb_window_t w)
|
||||
{
|
||||
int format;
|
||||
long result = -1;
|
||||
unsigned char *p = NULL;
|
||||
unsigned long n, extra;
|
||||
Atom real;
|
||||
if(XGetWindowProperty(globalconf.display, w, XInternAtom(globalconf.display, "WM_STATE", False),
|
||||
0L, 2L, False, XInternAtom(globalconf.display, "WM_STATE", False),
|
||||
&real, &format, &n, &extra, (unsigned char **) &p) != Success)
|
||||
xcb_get_property_cookie_t prop_c;
|
||||
xcb_atom_t wm_state_atom = x_intern_atom(globalconf.connection, "WM_STATE");
|
||||
xcb_get_property_reply_t *prop_r;
|
||||
|
||||
prop_c = xcb_get_property_unchecked(globalconf.connection, false, w,
|
||||
wm_state_atom, wm_state_atom,
|
||||
0L, 2L);
|
||||
|
||||
if((prop_r = xcb_get_property_reply(globalconf.connection, prop_c, NULL)) == NULL)
|
||||
return -1;
|
||||
if(n != 0)
|
||||
|
||||
p = xcb_get_property_value(prop_r);
|
||||
if(xcb_get_property_value_length(prop_r) != 0)
|
||||
result = *p;
|
||||
p_delete(&p);
|
||||
|
||||
p_delete(&prop_r);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -73,13 +83,12 @@ window_getstate(Window w)
|
|||
* \param border new border size
|
||||
* \return the XSendEvent() status
|
||||
*/
|
||||
Status
|
||||
window_configure(Window win, area_t geometry, int border)
|
||||
void
|
||||
window_configure(xcb_window_t win, area_t geometry, int border)
|
||||
{
|
||||
XConfigureEvent ce;
|
||||
xcb_configure_notify_event_t ce;
|
||||
|
||||
ce.type = ConfigureNotify;
|
||||
ce.display = globalconf.display;
|
||||
ce.response_type = XCB_CONFIGURE_NOTIFY;
|
||||
ce.event = win;
|
||||
ce.window = win;
|
||||
ce.x = geometry.x;
|
||||
|
@ -87,9 +96,9 @@ window_configure(Window win, area_t geometry, int border)
|
|||
ce.width = geometry.width;
|
||||
ce.height = geometry.height;
|
||||
ce.border_width = border;
|
||||
ce.above = None;
|
||||
ce.override_redirect = False;
|
||||
return XSendEvent(globalconf.display, win, False, StructureNotifyMask, (XEvent *) & ce);
|
||||
ce.above_sibling = XCB_NONE;
|
||||
ce.override_redirect = false;
|
||||
xcb_send_event(globalconf.connection, false, win, XCB_EVENT_MASK_STRUCTURE_NOTIFY, (char *) &ce);
|
||||
}
|
||||
|
||||
/** Grab or ungrab buttons on a window
|
||||
|
@ -97,32 +106,41 @@ window_configure(Window win, area_t geometry, int border)
|
|||
* \param phys_screen Physical screen number
|
||||
*/
|
||||
void
|
||||
window_grabbuttons(Window win, int phys_screen)
|
||||
window_grabbuttons(xcb_window_t win, int phys_screen)
|
||||
{
|
||||
Button *b;
|
||||
|
||||
XGrabButton(globalconf.display, Button1, NoSymbol,
|
||||
win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
|
||||
XGrabButton(globalconf.display, Button1, NoSymbol | LockMask,
|
||||
win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
|
||||
XGrabButton(globalconf.display, Button1, NoSymbol | globalconf.numlockmask,
|
||||
win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
|
||||
XGrabButton(globalconf.display, Button1, NoSymbol | globalconf.numlockmask | LockMask,
|
||||
win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
|
||||
xcb_grab_button(globalconf.connection, false, win, BUTTONMASK,
|
||||
XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE,
|
||||
XCB_BUTTON_INDEX_1, XCB_NO_SYMBOL);
|
||||
xcb_grab_button(globalconf.connection, false, win, BUTTONMASK,
|
||||
XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE,
|
||||
XCB_BUTTON_INDEX_1, XCB_NO_SYMBOL | XCB_MOD_MASK_LOCK);
|
||||
xcb_grab_button(globalconf.connection, false, win, BUTTONMASK,
|
||||
XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE,
|
||||
XCB_BUTTON_INDEX_1, XCB_NO_SYMBOL | globalconf.numlockmask);
|
||||
xcb_grab_button(globalconf.connection, false, win, BUTTONMASK,
|
||||
XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE,
|
||||
XCB_BUTTON_INDEX_1, XCB_NO_SYMBOL | globalconf.numlockmask | XCB_MOD_MASK_LOCK);
|
||||
|
||||
for(b = globalconf.buttons.client; b; b = b->next)
|
||||
{
|
||||
XGrabButton(globalconf.display, b->button, b->mod,
|
||||
win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
|
||||
XGrabButton(globalconf.display, b->button, b->mod | LockMask,
|
||||
win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
|
||||
XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask,
|
||||
win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
|
||||
XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask | LockMask,
|
||||
win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
|
||||
xcb_grab_button(globalconf.connection, false, win, BUTTONMASK,
|
||||
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE,
|
||||
b->button, b->mod);
|
||||
xcb_grab_button(globalconf.connection, false, win, BUTTONMASK,
|
||||
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE,
|
||||
b->button, b->mod | XCB_MOD_MASK_LOCK);
|
||||
xcb_grab_button(globalconf.connection, false, win, BUTTONMASK,
|
||||
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE,
|
||||
b->button, b->mod | globalconf.numlockmask);
|
||||
xcb_grab_button(globalconf.connection, false, win, BUTTONMASK,
|
||||
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE,
|
||||
b->button, b->mod | globalconf.numlockmask | XCB_MOD_MASK_LOCK);
|
||||
}
|
||||
|
||||
XUngrabButton(globalconf.display, AnyButton, AnyModifier, RootWindow(globalconf.display, phys_screen));
|
||||
xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY,
|
||||
root_window(globalconf.connection, phys_screen), ANY_MODIFIER);
|
||||
}
|
||||
|
||||
/** Grab buttons on root window
|
||||
|
@ -135,18 +153,22 @@ window_root_grabbuttons(int phys_screen)
|
|||
|
||||
for(b = globalconf.buttons.root; b; b = b->next)
|
||||
{
|
||||
XGrabButton(globalconf.display, b->button, b->mod,
|
||||
RootWindow(globalconf.display, phys_screen), False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
XGrabButton(globalconf.display, b->button, b->mod | LockMask,
|
||||
RootWindow(globalconf.display, phys_screen), False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask,
|
||||
RootWindow(globalconf.display, phys_screen), False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask | LockMask,
|
||||
RootWindow(globalconf.display, phys_screen), False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
xcb_grab_button(globalconf.connection, false,
|
||||
root_window(globalconf.connection, phys_screen), BUTTONMASK,
|
||||
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE,
|
||||
b->button, b->mod);
|
||||
xcb_grab_button(globalconf.connection, false,
|
||||
root_window(globalconf.connection, phys_screen), BUTTONMASK,
|
||||
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE,
|
||||
b->button, b->mod | XCB_MOD_MASK_LOCK);
|
||||
xcb_grab_button(globalconf.connection, false,
|
||||
root_window(globalconf.connection, phys_screen), BUTTONMASK,
|
||||
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE,
|
||||
b->button, b->mod | globalconf.numlockmask);
|
||||
xcb_grab_button(globalconf.connection, false,
|
||||
root_window(globalconf.connection, phys_screen), BUTTONMASK,
|
||||
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE,
|
||||
b->button, b->mod | globalconf.numlockmask | XCB_MOD_MASK_LOCK);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,56 +179,65 @@ void
|
|||
window_root_grabkeys(int phys_screen)
|
||||
{
|
||||
Key *k;
|
||||
KeyCode kc;
|
||||
xcb_keycode_t kc;
|
||||
xcb_key_symbols_t *keysyms;
|
||||
|
||||
XUngrabKey(globalconf.display, AnyKey, AnyModifier, RootWindow(globalconf.display, phys_screen));
|
||||
xcb_ungrab_key(globalconf.connection, ANY_KEY,
|
||||
root_window(globalconf.connection, phys_screen), ANY_MODIFIER);
|
||||
|
||||
keysyms = xcb_key_symbols_alloc(globalconf.connection);
|
||||
|
||||
for(k = globalconf.keys; k; k = k->next)
|
||||
if((kc = k->keycode) || (k->keysym && (kc = XKeysymToKeycode(globalconf.display, k->keysym))))
|
||||
if((kc = k->keycode) || (k->keysym && (kc = xcb_key_symbols_get_keycode(keysyms, k->keysym))))
|
||||
{
|
||||
XGrabKey(globalconf.display, kc, k->mod,
|
||||
RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync);
|
||||
XGrabKey(globalconf.display, kc, k->mod | LockMask,
|
||||
RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync);
|
||||
XGrabKey(globalconf.display, kc, k->mod | globalconf.numlockmask,
|
||||
RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync);
|
||||
XGrabKey(globalconf.display, kc, k->mod | globalconf.numlockmask | LockMask,
|
||||
RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync);
|
||||
xcb_grab_key(globalconf.connection, true, root_window(globalconf.connection, phys_screen),
|
||||
k->mod, kc, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
|
||||
xcb_grab_key(globalconf.connection, true, root_window(globalconf.connection, phys_screen),
|
||||
k->mod | XCB_MOD_MASK_LOCK, kc, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
|
||||
xcb_grab_key(globalconf.connection, true, root_window(globalconf.connection, phys_screen),
|
||||
k->mod | globalconf.numlockmask, kc, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
|
||||
xcb_grab_key(globalconf.connection, true, root_window(globalconf.connection, phys_screen),
|
||||
k->mod | globalconf.numlockmask | XCB_MOD_MASK_LOCK, kc, XCB_GRAB_MODE_ASYNC,
|
||||
XCB_GRAB_MODE_ASYNC);
|
||||
}
|
||||
|
||||
xcb_key_symbols_free(keysyms);
|
||||
}
|
||||
|
||||
void
|
||||
window_setshape(xcb_window_t win, int phys_screen)
|
||||
{
|
||||
xcb_shape_query_extents_reply_t *r;
|
||||
|
||||
/* Logic to decide if we have a shaped window cribbed from fvwm-2.5.10. */
|
||||
if((r = xcb_shape_query_extents_reply(globalconf.connection,
|
||||
xcb_shape_query_extents_unchecked(globalconf.connection, win),
|
||||
NULL)) && r->bounding_shaped)
|
||||
{
|
||||
xcb_shape_combine(globalconf.connection, XCB_SHAPE_SO_SET,
|
||||
XCB_SHAPE_SK_BOUNDING, XCB_SHAPE_SK_BOUNDING,
|
||||
root_window(globalconf.connection, phys_screen),
|
||||
0, 0, win);
|
||||
|
||||
p_delete(&r);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
window_setshape(Window win, int phys_screen)
|
||||
window_settrans(xcb_window_t win, double opacity)
|
||||
{
|
||||
int bounding_shaped, i, b;
|
||||
unsigned int u; /* dummies */
|
||||
|
||||
/* Logic to decide if we have a shaped window cribbed from fvwm-2.5.10. */
|
||||
if(XShapeQueryExtents(globalconf.display, win, &bounding_shaped, &i, &i,
|
||||
&u, &u, &b, &i, &i, &u, &u) && bounding_shaped)
|
||||
XShapeCombineShape(globalconf.display,
|
||||
RootWindow(globalconf.display, phys_screen),
|
||||
ShapeBounding, 0, 0, win, ShapeBounding, ShapeSet);
|
||||
}
|
||||
|
||||
int
|
||||
window_settrans(Window win, double opacity)
|
||||
{
|
||||
int status;
|
||||
unsigned int real_opacity = 0xffffffff;
|
||||
|
||||
if(opacity >= 0 && opacity <= 1)
|
||||
{
|
||||
real_opacity = opacity * 0xffffffff;
|
||||
status = XChangeProperty(globalconf.display, win,
|
||||
XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False),
|
||||
XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &real_opacity, 1L);
|
||||
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, win,
|
||||
x_intern_atom(globalconf.connection, "_NET_WM_WINDOW_OPACITY"),
|
||||
CARDINAL, 32, 1L, &real_opacity);
|
||||
}
|
||||
else
|
||||
status = XDeleteProperty(globalconf.display, win,
|
||||
XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False));
|
||||
|
||||
return status;
|
||||
xcb_delete_property(globalconf.connection, win,
|
||||
x_intern_atom(globalconf.connection, "_NET_WM_WINDOW_OPACITY"));
|
||||
}
|
||||
|
||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||
|
|
12
window.h
12
window.h
|
@ -24,14 +24,14 @@
|
|||
|
||||
#include "common/draw.h"
|
||||
|
||||
int window_setstate(Window, long);
|
||||
long window_getstate(Window);
|
||||
Status window_configure(Window, area_t, int);
|
||||
void window_grabbuttons(Window, int);
|
||||
void window_setstate(xcb_window_t, long);
|
||||
long window_getstate(xcb_window_t);
|
||||
void window_configure(xcb_window_t, area_t, int);
|
||||
void window_grabbuttons(xcb_window_t, int);
|
||||
void window_root_grabbuttons(int);
|
||||
void window_root_grabkeys(int);
|
||||
void window_setshape(Window, int);
|
||||
int window_settrans(Window, double);
|
||||
void window_setshape(xcb_window_t, int);
|
||||
void window_settrans(xcb_window_t, double);
|
||||
|
||||
#endif
|
||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||
|
|
|
@ -0,0 +1,192 @@
|
|||
/*
|
||||
* xcb_event_handler.c - xcb event handler
|
||||
*
|
||||
* Copyright © 2007-2008 Arnaud Fontaine <arnaud@andesi.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "xcb_event_handler.h"
|
||||
#include "common/util.h"
|
||||
|
||||
const char *x_label_error[] =
|
||||
{
|
||||
"Success",
|
||||
"BadRequest",
|
||||
"BadValue",
|
||||
"BadWindow",
|
||||
"BadPixmap",
|
||||
"BadAtom",
|
||||
"BadCursor",
|
||||
"BadFont",
|
||||
"BadMatch",
|
||||
"BadDrawable",
|
||||
"BadAccess",
|
||||
"BadAlloc",
|
||||
"BadColor",
|
||||
"BadGC",
|
||||
"BadIDChoice",
|
||||
"BadName",
|
||||
"BadLength",
|
||||
"BadImplementation",
|
||||
};
|
||||
|
||||
const char *x_label_request[] =
|
||||
{
|
||||
"XCB_NONE",
|
||||
"CreateWindow",
|
||||
"ChangeWindowAttributes",
|
||||
"GetWindowAttributes",
|
||||
"DestroyWindow",
|
||||
"DestroySubwindows",
|
||||
"ChangeSaveSet",
|
||||
"ReparentWindow",
|
||||
"MapWindow",
|
||||
"MapSubwindows",
|
||||
"UnmapWindow",
|
||||
"UnmapSubwindows",
|
||||
"ConfigureWindow",
|
||||
"CirculateWindow",
|
||||
"GetGeometry",
|
||||
"QueryTree",
|
||||
"InternAtom",
|
||||
"GetAtomName",
|
||||
"ChangeProperty",
|
||||
"DeleteProperty",
|
||||
"GetProperty",
|
||||
"ListProperties",
|
||||
"SetSelectionOwner",
|
||||
"GetSelectionOwner",
|
||||
"ConvertSelection",
|
||||
"SendEvent",
|
||||
"GrabPointer",
|
||||
"UngrabPointer",
|
||||
"GrabButton",
|
||||
"UngrabButton",
|
||||
"ChangeActivePointerGrab",
|
||||
"GrabKeyboard",
|
||||
"UngrabKeyboard",
|
||||
"GrabKey",
|
||||
"UngrabKey",
|
||||
"AllowEvents",
|
||||
"GrabServer",
|
||||
"UngrabServer",
|
||||
"QueryPointer",
|
||||
"GetMotionEvents",
|
||||
"TranslateCoords",
|
||||
"WarpPointer",
|
||||
"SetInputFocus",
|
||||
"GetInputFocus",
|
||||
"QueryKeymap",
|
||||
"OpenFont",
|
||||
"CloseFont",
|
||||
"QueryFont",
|
||||
"QueryTextExtents",
|
||||
"ListFonts",
|
||||
"ListFontsWithInfo",
|
||||
"SetFontPath",
|
||||
"GetFontPath",
|
||||
"CreatePixmap",
|
||||
"FreePixmap",
|
||||
"CreateGC",
|
||||
"ChangeGC",
|
||||
"CopyGC",
|
||||
"SetDashes",
|
||||
"SetClipRectangles",
|
||||
"FreeGC",
|
||||
"ClearArea",
|
||||
"CopyArea",
|
||||
"CopyPlane",
|
||||
"PolyPoint",
|
||||
"PolyLine",
|
||||
"PolySegment",
|
||||
"PolyRectangle",
|
||||
"PolyArc",
|
||||
"FillPoly",
|
||||
"PolyFillRectangle",
|
||||
"PolyFillArc",
|
||||
"PutImage",
|
||||
"GetImage",
|
||||
"PolyText",
|
||||
"PolyText",
|
||||
"ImageText",
|
||||
"ImageText",
|
||||
"CreateColormap",
|
||||
"FreeColormap",
|
||||
"CopyColormapAndFree",
|
||||
"InstallColormap",
|
||||
"UninstallColormap",
|
||||
"ListInstalledColormaps",
|
||||
"AllocColor",
|
||||
"AllocNamedColor",
|
||||
"AllocColorCells",
|
||||
"AllocColorPlanes",
|
||||
"FreeColors",
|
||||
"StoreColors",
|
||||
"StoreNamedColor",
|
||||
"QueryColors",
|
||||
"LookupColor",
|
||||
"CreateCursor",
|
||||
"CreateGlyphCursor",
|
||||
"FreeCursor",
|
||||
"RecolorCursor",
|
||||
"QueryBestSize",
|
||||
"QueryExtension",
|
||||
"ListExtensions",
|
||||
"ChangeKeyboardMapping",
|
||||
"GetKeyboardMapping",
|
||||
"ChangeKeyboardControl",
|
||||
"GetKeyboardControl",
|
||||
"Bell",
|
||||
"ChangePointerControl",
|
||||
"GetPointerControl",
|
||||
"SetScreenSaver",
|
||||
"GetScreenSaver",
|
||||
"ChangeHosts",
|
||||
"ListHosts",
|
||||
"SetAccessControl",
|
||||
"SetCloseDownMode",
|
||||
"KillClient",
|
||||
"RotateProperties",
|
||||
"ForceScreenSaver",
|
||||
"SetPointerMapping",
|
||||
"GetPointerMapping",
|
||||
"SetModifierMapping",
|
||||
"GetModifierMapping",
|
||||
"major 120",
|
||||
"major 121",
|
||||
"major 122",
|
||||
"major 123",
|
||||
"major 124",
|
||||
"major 125",
|
||||
"major 126",
|
||||
"NoOperation",
|
||||
};
|
||||
|
||||
/** Set the same handler for all errors
|
||||
*/
|
||||
void
|
||||
xcb_set_error_handler_catch_all(xcb_event_handlers_t *evenths,
|
||||
xcb_generic_error_handler_t handler,
|
||||
void *data)
|
||||
{
|
||||
int err_num;
|
||||
for(err_num = 0; err_num < ERRORS_NBR; err_num++)
|
||||
xcb_set_error_handler(evenths, err_num, handler, data);
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* xcb_event_handler.c - xcb event handler header
|
||||
*
|
||||
* Copyright © 2007-2008 Arnaud Fontaine <arnaud@andesi.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef XCB_EVENT_HANDLER_H
|
||||
#define XCB_EVENT_HANDLER_H
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_event.h>
|
||||
|
||||
/* Set the same handler for all errors */
|
||||
void xcb_set_error_handler_catch_all(xcb_event_handlers_t *,
|
||||
xcb_generic_error_handler_t,
|
||||
void *);
|
||||
|
||||
/* Number of different errors */
|
||||
#define ERRORS_NBR 256
|
||||
|
||||
/* Number of different events */
|
||||
#define EVENTS_NBR 126
|
||||
|
||||
/* Get the error name from its code */
|
||||
extern const char *x_label_error[];
|
||||
|
||||
/* Get a request name from its code */
|
||||
extern const char *x_label_request[];
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue