Add python wmfslib
This commit is contained in:
44
src/config.c
44
src/config.c
@@ -33,6 +33,48 @@
|
||||
#include "config_struct.h"
|
||||
|
||||
|
||||
void
|
||||
conf_init_func_list(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
func_name_list_t tmp_list[] =
|
||||
{
|
||||
{"spawn", uicb_spawn },
|
||||
{"client_kill", uicb_client_kill },
|
||||
{"client_prev", uicb_client_prev },
|
||||
{"client_next", uicb_client_next },
|
||||
{"toggle_max", uicb_togglemax },
|
||||
{"layout_next", uicb_layout_next },
|
||||
{"layout_prev", uicb_layout_prev },
|
||||
{"tag", uicb_tag },
|
||||
{"tag_next", uicb_tag_next },
|
||||
{"tag_prev", uicb_tag_prev },
|
||||
{"tag_transfert", uicb_tagtransfert },
|
||||
{"set_mwfact", uicb_set_mwfact },
|
||||
{"set_nmaster", uicb_set_nmaster },
|
||||
{"quit", uicb_quit },
|
||||
{"toggle_infobar_position", uicb_infobar_togglepos },
|
||||
{"mouse_move", uicb_mouse_move },
|
||||
{"mouse_resize", uicb_mouse_resize },
|
||||
{"client_raise", uicb_client_raise },
|
||||
{"tile_switch", uicb_tile_switch },
|
||||
{"toggle_free", uicb_togglefree },
|
||||
{"screen_select", uicb_screen_select },
|
||||
{"screen_next", uicb_screen_next },
|
||||
{"screen_prev", uicb_screen_prev },
|
||||
{"reload", uicb_reload }
|
||||
};
|
||||
|
||||
func_list = emalloc(LEN(tmp_list), sizeof(func_name_list_t));
|
||||
|
||||
for(i = 0; i < LEN(tmp_list); ++i)
|
||||
func_list[i] = tmp_list[i];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* The following function are the
|
||||
different configuration section. {{{
|
||||
*/
|
||||
@@ -301,6 +343,8 @@ init_conf(void)
|
||||
ret = cfg_parse(cfg, final_path);
|
||||
}
|
||||
|
||||
conf_init_func_list();
|
||||
|
||||
conf_alias_section(cfg_getsec(cfg, "alias"));
|
||||
conf_misc_section(cfg_getsec(cfg, "misc"));
|
||||
conf_bar_section(cfg_getsec(cfg, "bar"));
|
||||
|
||||
@@ -172,34 +172,6 @@ cfg_opt_t opts[] =
|
||||
CFG_END()
|
||||
};
|
||||
|
||||
func_name_list_t func_list[] =
|
||||
{
|
||||
{"spawn", uicb_spawn },
|
||||
{"client_kill", uicb_client_kill },
|
||||
{"client_prev", uicb_client_prev },
|
||||
{"client_next", uicb_client_next },
|
||||
{"toggle_max", uicb_togglemax },
|
||||
{"layout_next", uicb_layout_next },
|
||||
{"layout_prev", uicb_layout_prev },
|
||||
{"tag", uicb_tag },
|
||||
{"tag_next", uicb_tag_next },
|
||||
{"tag_prev", uicb_tag_prev },
|
||||
{"tag_transfert", uicb_tagtransfert },
|
||||
{"set_mwfact", uicb_set_mwfact },
|
||||
{"set_nmaster", uicb_set_nmaster },
|
||||
{"quit", uicb_quit },
|
||||
{"toggle_infobar_position", uicb_infobar_togglepos },
|
||||
{"mouse_move", uicb_mouse_move },
|
||||
{"mouse_resize", uicb_mouse_resize },
|
||||
{"client_raise", uicb_client_raise },
|
||||
{"tile_switch", uicb_tile_switch },
|
||||
{"toggle_free", uicb_togglefree },
|
||||
{"screen_select", uicb_screen_select },
|
||||
{"screen_next", uicb_screen_next },
|
||||
{"screen_prev", uicb_screen_prev },
|
||||
{"reload", uicb_reload }
|
||||
};
|
||||
|
||||
func_name_list_t layout_list[] =
|
||||
{
|
||||
{"tile_right", tile },
|
||||
|
||||
67
src/event.c
67
src/event.c
@@ -32,6 +32,8 @@
|
||||
|
||||
#include "wmfs.h"
|
||||
|
||||
//#include "config_struct.h"
|
||||
|
||||
/** ButtonPress handle event
|
||||
* \param ev XButtonEvent pointer
|
||||
*/
|
||||
@@ -100,6 +102,9 @@ clientmessageevent(XClientMessageEvent *ev)
|
||||
{
|
||||
Client *c;
|
||||
int i, mess_t = 0;
|
||||
Atom rt;
|
||||
int rf;
|
||||
ulong ir, il;
|
||||
|
||||
if(ev->format != 32)
|
||||
return;
|
||||
@@ -116,25 +121,87 @@ clientmessageevent(XClientMessageEvent *ev)
|
||||
&& ev->data.l[0] < conf.ntag[selscreen])
|
||||
tag_set((int)(ev->data.l[0] + 1));
|
||||
|
||||
/* Manage _WMFS_SET_SCREEN */
|
||||
if(mess_t == wmfs_set_screen
|
||||
&& ev->data.l[0] >= 0
|
||||
&& ev->data.l[0] <= screen_count())
|
||||
screen_set_sel((int)(ev->data.l[0]));
|
||||
|
||||
/* Manage _NET_ACTIVE_WINDOW */
|
||||
else if(mess_t == net_active_window)
|
||||
if((c = client_gb_win(ev->window)))
|
||||
client_focus(c);
|
||||
}
|
||||
|
||||
|
||||
/* Manage _NET_WM_STATE */
|
||||
if(mess_t == net_wm_state)
|
||||
if((c = client_gb_win(ev->window)))
|
||||
ewmh_manage_net_wm_state(ev->data.l, c);
|
||||
|
||||
/* Manage _NET_CLOSE_WINDOW */
|
||||
if(mess_t == net_close_window)
|
||||
if((c = client_gb_win(ev->window)))
|
||||
client_kill(c);
|
||||
|
||||
/* Manage _NET_WM_DESKTOP */
|
||||
if(mess_t == net_wm_desktop)
|
||||
if((c = client_gb_win(ev->window)))
|
||||
tag_transfert(c, ev->data.l[0]);
|
||||
|
||||
/* Manage _WMFS_STATUSTEXT */
|
||||
if(mess_t == wmfs_statustext && ev->data.l[4] == True)
|
||||
{
|
||||
uchar *ret;
|
||||
|
||||
if(XGetWindowProperty(dpy, ROOT, net_atom[wmfs_statustext], 0, 4096,
|
||||
False, net_atom[utf8_string], &rt, &rf, &ir, &il, &ret) == Success)
|
||||
{
|
||||
for(i = 0; i < LEN(statustext); ++i)
|
||||
statustext[i] = 0;
|
||||
|
||||
strcpy(statustext, (char*)ret);
|
||||
|
||||
for(i = 0; i < screen_count(); ++i)
|
||||
infobar_draw(i);
|
||||
|
||||
XFree(ret);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(mess_t == wmfs_function && ev->data.l[4] == True)
|
||||
{
|
||||
uchar *ret_func = NULL;
|
||||
uchar *ret_cmd = NULL;
|
||||
char *cmd;
|
||||
|
||||
if(XGetWindowProperty(dpy, ROOT, net_atom[wmfs_function], 0, 4096,
|
||||
False, net_atom[utf8_string], &rt, &rf, &ir, &il, &ret_func) == Success)
|
||||
printf("--> %s -> ", ret_func);
|
||||
|
||||
if(XGetWindowProperty(dpy, ROOT, net_atom[wmfs_cmd], 0, 4096,
|
||||
False, net_atom[utf8_string], &rt, &rf, &ir, &il, &ret_cmd) == Success)
|
||||
printf("%s\n", ret_cmd);
|
||||
|
||||
if(strcmp((char*)ret_cmd, "NULL") == 0)
|
||||
cmd = NULL;
|
||||
else
|
||||
strcpy(cmd, (char*)ret_cmd);
|
||||
|
||||
void (*func)(uicb_t) = name_to_func((char*)ret_func, func_list);
|
||||
|
||||
func(cmd);
|
||||
|
||||
if(ret_cmd)
|
||||
XFree(ret_cmd);
|
||||
|
||||
if(ret_func)
|
||||
XFree(ret_func);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
46
src/ewmh.c
46
src/ewmh.c
@@ -42,6 +42,8 @@
|
||||
void
|
||||
ewmh_init_hints(void)
|
||||
{
|
||||
int i = 1;
|
||||
|
||||
/* EWMH hints */
|
||||
net_atom[net_supported] = ATOM("_NET_SUPPORTED");
|
||||
net_atom[net_client_list] = ATOM("_NET_CLIENT_LIST");
|
||||
@@ -67,13 +69,26 @@ ewmh_init_hints(void)
|
||||
net_atom[net_wm_state_fullscreen] = ATOM("_NET_WM_STATE_FULLSCREEN");
|
||||
net_atom[net_wm_state_demands_attention] = ATOM("_NET_WM_STATE_DEMANDS_ATTENTION");
|
||||
net_atom[utf8_string] = ATOM("UTF8_STRING");
|
||||
|
||||
/* WMFS hints */
|
||||
net_atom[wmfs_tag_names] = ATOM("_WMFS_TAG_NAMES");
|
||||
net_atom[wmfs_running] = ATOM("_WMFS_RUNNING");
|
||||
net_atom[wmfs_statustext] = ATOM("_WMFS_STATUSTEXT");
|
||||
net_atom[wmfs_set_screen] = ATOM("_WMFS_SET_SCREEN");
|
||||
net_atom[wmfs_screen_count] = ATOM("_WMFS_SCREEN_COUNT");
|
||||
net_atom[wmfs_current_tag] = ATOM("_WMFS_CURRENT_TAG");
|
||||
net_atom[wmfs_current_screen] = ATOM("_WMFS_CURRENT_SCREEN");
|
||||
net_atom[wmfs_current_layout] = ATOM("_WMFS_CURRENT_LAYOUT");
|
||||
net_atom[wmfs_tag_names] = ATOM("_WMFS_TAG_NAMES");
|
||||
|
||||
net_atom[wmfs_function] = ATOM("_WMFS_FUNCTION");
|
||||
net_atom[wmfs_cmd] = ATOM("_WMFS_CMD");
|
||||
|
||||
XChangeProperty(dpy, ROOT, net_atom[net_supported], XA_ATOM, 32,
|
||||
PropModeReplace, (uchar*)net_atom, net_last);
|
||||
|
||||
XChangeProperty(dpy, ROOT, net_atom[wmfs_running], XA_CARDINAL, 32,
|
||||
PropModeReplace, (uchar*)&i, 1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -107,6 +122,11 @@ ewmh_get_current_desktop(void)
|
||||
XChangeProperty(dpy, ROOT, net_atom[net_current_desktop], XA_CARDINAL, 32,
|
||||
PropModeReplace, (uchar*)&t, 1);
|
||||
|
||||
/* Current tag name */
|
||||
XChangeProperty(dpy, ROOT, net_atom[wmfs_current_tag], net_atom[utf8_string], 8,
|
||||
PropModeReplace, (uchar*)tags[selscreen][seltag[selscreen]].name,
|
||||
strlen(tags[selscreen][seltag[selscreen]].name));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -308,27 +328,3 @@ ewmh_manage_window_type(Client *c)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/** Get a Window WM State
|
||||
* \param win Window
|
||||
* \return The state
|
||||
*/
|
||||
long
|
||||
ewmh_get_wm_state(Window win)
|
||||
{
|
||||
Atom rt;
|
||||
int rf;
|
||||
long ret = WithdrawnState;
|
||||
ulong ir, il;
|
||||
uchar *data;
|
||||
|
||||
if(XGetWindowProperty(dpy, win, net_atom[net_wm_state], 0L, 2L,
|
||||
False, net_atom[net_wm_state], &rt,
|
||||
&rf, &ir, &il, &data) == Success && ir)
|
||||
{
|
||||
ret = *(long *)data;
|
||||
XFree(data);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ frame_create(Client *c)
|
||||
if(TBARH)
|
||||
c->titlebar = barwin_create(c->frame, 0, 0,
|
||||
c->frame_geo.width,
|
||||
TBARH + BORDH,
|
||||
TBARH + (c->geo.x - c->frame_geo.x),
|
||||
c->colors.frame,
|
||||
c->colors.fg,
|
||||
True, conf.titlebar.stipple);
|
||||
@@ -191,8 +191,7 @@ frame_update(Client *c)
|
||||
XClearWindow(dpy, c->bottom);
|
||||
|
||||
if(TBARH && (TBARH + BORDH + 1) > font->height)
|
||||
barwin_draw_text(c->titlebar,
|
||||
(c->frame_geo.width / 2) - (textw(c->title) / 2),
|
||||
barwin_draw_text(c->titlebar, (c->frame_geo.width / 2) - (textw(c->title) / 2),
|
||||
(font->height - (font->descent)) + (((TBARH + BORDH) - font->height) / 2),
|
||||
c->title);
|
||||
|
||||
|
||||
@@ -135,13 +135,10 @@ infobar_draw_taglist(int sc)
|
||||
{
|
||||
if(c->screen == sc)
|
||||
{
|
||||
infobar[sc].tags[c->tag]->bg = ((c->tag == seltag[sc])
|
||||
? conf.colors.tagselbg
|
||||
: conf.colors.tag_occupied_bg);
|
||||
infobar[sc].tags[c->tag]->bg = ((c->tag == seltag[sc]) ? conf.colors.tagselbg : conf.colors.tag_occupied_bg);
|
||||
barwin_refresh_color(infobar[sc].tags[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if(tags[sc][i].name)
|
||||
barwin_draw_text(infobar[sc].tags[i], PAD / 2, font->height, tags[sc][i].name);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,6 @@ init(void)
|
||||
init_key();
|
||||
init_root();
|
||||
screen_init_geo();
|
||||
ewmh_init_hints();
|
||||
infobar_init();
|
||||
ewmh_get_current_desktop();
|
||||
grabkeys();
|
||||
|
||||
@@ -45,6 +45,10 @@ screen_count(void)
|
||||
else
|
||||
n = ScreenCount(dpy);
|
||||
|
||||
/* Set _WMFS_SCREEN_COUNT */
|
||||
XChangeProperty(dpy, ROOT, net_atom[wmfs_screen_count], XA_CARDINAL, 32,
|
||||
PropModeReplace, (uchar*)&n, 1);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
@@ -135,6 +139,10 @@ screen_get_sel(void)
|
||||
XQueryPointer(dpy, ROOT, &w, &w, &x, &y, &d, &d, (uint *)&u);
|
||||
|
||||
selscreen = screen_get_with_geo(x, y);
|
||||
|
||||
/* Set _WMFS_CURRENT_SCREEN */
|
||||
XChangeProperty(dpy, ROOT, net_atom[wmfs_current_screen], XA_CARDINAL, 32,
|
||||
PropModeReplace, (uchar*)&selscreen, 1);
|
||||
}
|
||||
|
||||
return selscreen;
|
||||
|
||||
@@ -78,8 +78,16 @@ enum
|
||||
net_wm_state_demands_attention,
|
||||
utf8_string,
|
||||
/* WMFS HINTS */
|
||||
wmfs_running,
|
||||
wmfs_tag_names,
|
||||
wmfs_current_tag,
|
||||
wmfs_current_screen,
|
||||
wmfs_current_layout,
|
||||
wmfs_set_screen,
|
||||
wmfs_screen_count,
|
||||
wmfs_statustext,
|
||||
wmfs_function,
|
||||
wmfs_cmd,
|
||||
net_last
|
||||
};
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ setwinstate(Window win, long state)
|
||||
usage. {{{
|
||||
*/
|
||||
void*
|
||||
name_to_func(char *name, func_name_list_t l[])
|
||||
name_to_func(char *name, func_name_list_t *l)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
||||
@@ -107,6 +107,7 @@ quit(void)
|
||||
free(infobar);
|
||||
free(seltag);
|
||||
free(keys);
|
||||
free(func_list);
|
||||
free(conf.ntag);
|
||||
free(conf.titlebar.mouse);
|
||||
free(conf.client.mouse);
|
||||
@@ -313,6 +314,8 @@ main(int argc, char **argv)
|
||||
XSetErrorHandler(errorhandler);
|
||||
|
||||
/* Let's Go ! */
|
||||
|
||||
ewmh_init_hints();
|
||||
init_conf();
|
||||
init();
|
||||
scan();
|
||||
|
||||
@@ -80,7 +80,7 @@
|
||||
#define FRAMEH(h) h + (BORDH * 2) + TBARH
|
||||
#define RESHW 5 * BORDH
|
||||
#define CHECK(x) if(!x) return
|
||||
#define ITOA(p ,n) sprintf(p, "%d", n)
|
||||
#define LEN(x) (sizeof(x) / sizeof(x[0]))
|
||||
#define deb(p) fprintf(stderr, "debug: %d\n", p)
|
||||
#define PAD 14
|
||||
|
||||
@@ -157,7 +157,6 @@ void ewmh_set_desktop_geometry(void);
|
||||
void ewmh_set_workarea(void);
|
||||
void ewmh_manage_net_wm_state(long data_l[], Client *c);
|
||||
void ewmh_manage_window_type(Client *c);
|
||||
long ewmh_get_wm_state(Window win);
|
||||
|
||||
/* frame.c */
|
||||
void frame_create(Client *c);
|
||||
@@ -203,7 +202,7 @@ void *emalloc(uint element, uint size);
|
||||
ulong getcolor(char *color);
|
||||
void setwinstate(Window win, long state);
|
||||
/* Conf usage {{{ */
|
||||
void* name_to_func(char *name, func_name_list_t l[]);
|
||||
void* name_to_func(char *name, func_name_list_t *l);
|
||||
ulong char_to_modkey(char *name, key_name_list_t key_l[]);
|
||||
uint char_to_button(char *name, name_to_uint_t blist[]);
|
||||
Layout layout_name_to_struct(Layout lt[], char *name, int n, func_name_list_t llist[]);
|
||||
@@ -297,6 +296,7 @@ Client *clients;
|
||||
Client *sel;
|
||||
|
||||
/* Other */
|
||||
func_name_list_t *func_list;
|
||||
uint numlockmask;
|
||||
|
||||
#endif /* WMFS_H */
|
||||
|
||||
Reference in New Issue
Block a user