mirror of
https://github.com/0intro/wmii
synced 2024-11-22 13:52:17 +03:00
changed libwmii signatures, removed win_prop, using XGetWMName instead (more modern)
This commit is contained in:
parent
2d3b1e9d80
commit
9142b6a7ab
@ -14,15 +14,16 @@ Client *alloc_client(Window w)
|
||||
{
|
||||
static int id = 0;
|
||||
char buf[MAX_BUF];
|
||||
char buf2[MAX_BUF];
|
||||
XTextProperty name;
|
||||
Client *c = (Client *) cext_emallocz(sizeof(Client));
|
||||
|
||||
c->win = w;
|
||||
snprintf(buf, MAX_BUF, "/detached/client/%d", id);
|
||||
c->file[C_PREFIX] = ixp_create(ixps, buf);
|
||||
win_prop(dpy, c->win, XA_WM_NAME, buf2, MAX_BUF);
|
||||
XGetWMName(dpy, c->win, &name);
|
||||
snprintf(buf, MAX_BUF, "/detached/client/%d/name", id);
|
||||
c->file[C_NAME] = wmii_create_ixpfile(ixps, buf, buf2);
|
||||
c->file[C_NAME] = wmii_create_ixpfile(ixps, buf, (char *)name.value);
|
||||
free(name.value);
|
||||
id++;
|
||||
cext_attach_item(&clients, c);
|
||||
return c;
|
||||
@ -117,7 +118,7 @@ void configure_client(Client * c)
|
||||
void close_client(Client * c)
|
||||
{
|
||||
if (c->proto & PROTO_DEL)
|
||||
send_message(dpy, c->win, wm_protocols, wm_delete);
|
||||
wmii_send_message(dpy, c->win, wm_protocols, wm_delete);
|
||||
else
|
||||
XKillClient(dpy, c->win);
|
||||
}
|
||||
@ -142,10 +143,9 @@ void init_client(Client * c, XWindowAttributes * wa)
|
||||
|
||||
void handle_client_property(Client * c, XPropertyEvent * e)
|
||||
{
|
||||
char buf[1024];
|
||||
XTextProperty name;
|
||||
long msize;
|
||||
|
||||
buf[0] = 0;
|
||||
if (e->state == PropertyDelete)
|
||||
return; /* ignore */
|
||||
|
||||
@ -156,13 +156,14 @@ void handle_client_property(Client * c, XPropertyEvent * e)
|
||||
}
|
||||
switch (e->atom) {
|
||||
case XA_WM_NAME:
|
||||
win_prop(dpy, c->win, XA_WM_NAME, buf, sizeof(buf));
|
||||
if (strlen(buf)) {
|
||||
XGetWMName(dpy, c->win, &name);
|
||||
if (strlen((char *)name.value)) {
|
||||
if (c->file[C_NAME]->content)
|
||||
free(c->file[C_NAME]->content);
|
||||
c->file[C_NAME]->content = cext_estrdup(buf);
|
||||
c->file[C_NAME]->size = strlen(buf);
|
||||
c->file[C_NAME]->content = cext_estrdup((char *)name.value);
|
||||
c->file[C_NAME]->size = strlen((char *)name.value);
|
||||
}
|
||||
free(name.value);
|
||||
if (c->frame)
|
||||
draw_client(c, nil);
|
||||
invoke_wm_event(def[WM_EVENT_CLIENT_UPDATE]);
|
||||
|
@ -295,7 +295,7 @@ void handle_frame_buttonpress(XButtonEvent *e, Frame *f)
|
||||
bindex = F_EVENT_B2PRESS - 2 + e->button;
|
||||
/* frame mouse handling */
|
||||
if (f->file[bindex]->content)
|
||||
spawn(dpy, f->file[bindex]->content);
|
||||
wmii_spawn(dpy, f->file[bindex]->content);
|
||||
draw_frame(f, nil);
|
||||
}
|
||||
|
||||
|
10
cmd/wm/wm.c
10
cmd/wm/wm.c
@ -90,7 +90,7 @@ void invoke_wm_event(File * f)
|
||||
{
|
||||
if (!f->content)
|
||||
return;
|
||||
spawn(dpy, f->content);
|
||||
wmii_spawn(dpy, f->content);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -481,8 +481,7 @@ int win_proto(Window w)
|
||||
int protos = 0;
|
||||
int i;
|
||||
|
||||
res = property(dpy, w, wm_protocols, XA_ATOM,
|
||||
20L, ((unsigned char **) &protocols));
|
||||
res = wmii_property(dpy, w, wm_protocols, XA_ATOM, 20L, ((unsigned char **) &protocols));
|
||||
if (res <= 0) {
|
||||
return protos;
|
||||
}
|
||||
@ -502,8 +501,7 @@ int win_state(Window w)
|
||||
int res;
|
||||
|
||||
long *prop = 0;
|
||||
if (property(dpy, w, wm_state, wm_state,
|
||||
2L, ((unsigned char **) &prop)) > 0) {
|
||||
if (wmii_property(dpy, w, wm_state, wm_state, 2L, ((unsigned char **) &prop)) > 0) {
|
||||
res = (int) *prop;
|
||||
free((long *) prop);
|
||||
} else {
|
||||
@ -754,7 +752,7 @@ int main(int argc, char *argv[])
|
||||
init_cursors();
|
||||
init_default();
|
||||
font = blitz_getfont(dpy, def[WM_FONT]->content);
|
||||
init_lock_modifiers(dpy, &valid_mask, &num_lock_mask);
|
||||
wmii_init_lock_modifiers(dpy, &valid_mask, &num_lock_mask);
|
||||
init_screen();
|
||||
init_layouts();
|
||||
scan_wins();
|
||||
|
@ -328,7 +328,7 @@ static void iter_buttonpress(void *item, void *bpress)
|
||||
snprintf(buf, MAX_BUF, "%s/b%upress", path, e->button);
|
||||
if ((p = ixp_walk(ixps, buf)))
|
||||
if (p->content)
|
||||
spawn(dpy, p->content);
|
||||
wmii_spawn(dpy, p->content);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ static void handle_shortcut_chain(Window w, Shortcut * processed, char *prefix,
|
||||
emulate_key_press(mod, key);
|
||||
} else if ((s->mod == mod) && (s->key == key)) {
|
||||
if (s->cmdfile && s->cmdfile->content)
|
||||
spawn(dpy, s->cmdfile->content);
|
||||
wmii_spawn(dpy, s->cmdfile->content);
|
||||
else if (s->next) {
|
||||
snprintf(buf, sizeof(buf), "%s/%s", prefix, s->name);
|
||||
handle_shortcut_chain(w, s, buf, 0);
|
||||
@ -236,7 +236,7 @@ static void handle_shortcut_gkb(Window w, unsigned long mod, KeyCode key)
|
||||
|
||||
s = cext_find_item(&shortcuts, &comp, comp_shortcut);
|
||||
if (s && s->cmdfile && s->cmdfile->content) {
|
||||
spawn(dpy, s->cmdfile->content);
|
||||
wmii_spawn(dpy, s->cmdfile->content);
|
||||
return;
|
||||
}
|
||||
XBell(dpy, 0);
|
||||
@ -253,7 +253,7 @@ static void handle_shortcut(Window w, unsigned long mod, KeyCode key)
|
||||
|
||||
s = cext_find_item(&shortcuts, &comp, comp_shortcut);
|
||||
if (s && s->cmdfile && s->cmdfile->content) {
|
||||
spawn(dpy, s->cmdfile->content);
|
||||
wmii_spawn(dpy, s->cmdfile->content);
|
||||
return;
|
||||
}
|
||||
if (s && s->next)
|
||||
@ -456,7 +456,7 @@ int main(int argc, char *argv[])
|
||||
krect.x = krect.y = 0;
|
||||
krect.width = krect.height = 1;
|
||||
|
||||
init_lock_modifiers(dpy, &valid_mask, &num_lock_mask);
|
||||
wmii_init_lock_modifiers(dpy, &valid_mask, &num_lock_mask);
|
||||
|
||||
win = XCreateWindow(dpy, RootWindow(dpy, screen_num), krect.x, krect.y,
|
||||
krect.width, krect.height, 0, DefaultDepth(dpy, screen_num),
|
||||
|
@ -111,7 +111,7 @@ static void exec_item(char *cmd)
|
||||
snprintf(rc, len, "%s %s", (char *) files[M_PRE_COMMAND]->content, cmd);
|
||||
}
|
||||
/* fallback */
|
||||
spawn(dpy, rc);
|
||||
wmii_spawn(dpy, rc);
|
||||
/* cleanup */
|
||||
if (files[M_PRE_COMMAND]->content)
|
||||
free(rc);
|
||||
|
@ -6,7 +6,7 @@ include ../config.mk
|
||||
CFLAGS += -I../liblitz -I../libixp -I../libcext
|
||||
LDFLAGS += -L../liblitz -llitz -L../libixp -lixp -L../libcext -lcext
|
||||
|
||||
SRC = ixputil.c spawn.c util.c wm.c
|
||||
SRC = ixputil.c spawn.c wm.c
|
||||
|
||||
OBJ = ${SRC:.c=.o}
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
#include "wmii.h"
|
||||
|
||||
void spawn(void *dpy, char *cmd)
|
||||
void wmii_spawn(void *dpy, char *cmd)
|
||||
{
|
||||
/* the questionable double-fork is done to catch all zombies */
|
||||
if (fork() == 0) {
|
||||
|
@ -1,13 +0,0 @@
|
||||
/*
|
||||
* (C)opyright MMIV-MMV Anselm R. Garbe <garbeam at gmail dot com>
|
||||
* See LICENSE file for license details.
|
||||
*/
|
||||
|
||||
#include "wmii.h"
|
||||
|
||||
void swap(void **p1, void **p2)
|
||||
{
|
||||
void *tmp = *p1;
|
||||
*p1 = *p2;
|
||||
*p2 = tmp;
|
||||
}
|
23
libwmii/wm.c
23
libwmii/wm.c
@ -13,15 +13,14 @@
|
||||
|
||||
#include "blitz.h"
|
||||
|
||||
int property(Display * dpy, Window w, Atom a, Atom t, long l, unsigned char **prop)
|
||||
int wmii_property(Display * dpy, Window w, Atom a, Atom t, long l, unsigned char **prop)
|
||||
{
|
||||
Atom real;
|
||||
int format;
|
||||
unsigned long res, extra;
|
||||
int status;
|
||||
|
||||
status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format,
|
||||
&res, &extra, prop);
|
||||
status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format, &res, &extra, prop);
|
||||
|
||||
if (status != Success || *prop == 0) {
|
||||
return 0;
|
||||
@ -32,19 +31,7 @@ int property(Display * dpy, Window w, Atom a, Atom t, long l, unsigned char **pr
|
||||
return res;
|
||||
}
|
||||
|
||||
void win_prop(Display * dpy, Window w, Atom a, char *res, int len)
|
||||
{
|
||||
unsigned char *prop;
|
||||
|
||||
if (property(dpy, w, a, XA_STRING, 100L, &prop)) {
|
||||
cext_strlcpy(res, (char *) prop, len);
|
||||
XFree(prop);
|
||||
}
|
||||
res[len - 1] = 0;
|
||||
XSync(dpy, False);
|
||||
}
|
||||
|
||||
void send_message(Display * dpy, Window w, Atom a, long value)
|
||||
void wmii_send_message(Display * dpy, Window w, Atom a, long value)
|
||||
{
|
||||
XEvent e;
|
||||
e.type = ClientMessage;
|
||||
@ -59,9 +46,7 @@ void send_message(Display * dpy, Window w, Atom a, long value)
|
||||
}
|
||||
|
||||
#define NUM_MASKS 8
|
||||
void
|
||||
init_lock_modifiers(Display * dpy, unsigned int *valid_mask,
|
||||
unsigned int *num_lock_mask)
|
||||
void wmii_init_lock_modifiers(Display * dpy, unsigned int *valid_mask, unsigned int *num_lock_mask)
|
||||
{
|
||||
XModifierKeymap *modmap;
|
||||
KeyCode num_lock;
|
||||
|
@ -23,17 +23,9 @@ void wmii_move_ixpfile(File * f, File * to_parent);
|
||||
IXPServer *wmii_setup_server(char *sockfile);
|
||||
|
||||
/* spawn.c */
|
||||
void spawn(void *dpy, char *cmd);
|
||||
|
||||
/* util.c */
|
||||
void swap(void **p1, void **p2);
|
||||
void wmii_spawn(void *dpy, char *cmd);
|
||||
|
||||
/* wm.c */
|
||||
int
|
||||
property(Display * dpy, Window w, Atom a, Atom t, long l,
|
||||
unsigned char **prop);
|
||||
void win_prop(Display * dpy, Window w, Atom a, char *res, int len);
|
||||
void send_message(Display * dpy, Window w, Atom a, long value);
|
||||
void
|
||||
init_lock_modifiers(Display * dpy, unsigned int *valid_mask,
|
||||
unsigned int *num_lock_mask);
|
||||
int wmii_property(Display *dpy, Window w, Atom a, Atom t, long l, unsigned char **prop);
|
||||
void wmii_send_message(Display *dpy, Window w, Atom a, long value);
|
||||
void wmii_init_lock_modifiers(Display *dpy, unsigned int *valid_mask, unsigned int *num_lock_mask);
|
||||
|
Loading…
Reference in New Issue
Block a user