wmii/libwmii/wm.c

82 lines
1.9 KiB
C
Raw Normal View History

2005-11-18 18:54:58 +03:00
/*
2006-01-20 17:20:24 +03:00
* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
2005-11-18 18:54:58 +03:00
* See LICENSE file for license details.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include "blitz.h"
2005-12-21 18:18:11 +03:00
int
wmii_property(Display * dpy, Window w, Atom a, Atom t, long l,
unsigned char **prop)
2005-11-18 18:54:58 +03:00
{
2005-12-21 18:18:11 +03:00
Atom real;
int format;
unsigned long res, extra;
int status;
2005-11-18 18:54:58 +03:00
2005-12-21 18:18:11 +03:00
status =
XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format,
&res, &extra, prop);
2005-11-18 18:54:58 +03:00
2005-12-21 18:18:11 +03:00
if(status != Success || *prop == 0) {
return 0;
}
if(res == 0) {
free((void *) *prop);
}
return res;
2005-11-18 18:54:58 +03:00
}
2005-12-21 18:18:11 +03:00
void
wmii_send_message(Display * dpy, Window w, Atom a, long value)
2005-11-18 18:54:58 +03:00
{
2005-12-21 18:18:11 +03:00
XEvent e;
e.type = ClientMessage;
e.xclient.window = w;
e.xclient.message_type = a;
e.xclient.format = 32;
e.xclient.data.l[0] = value;
e.xclient.data.l[1] = CurrentTime;
2005-11-18 18:54:58 +03:00
2005-12-21 18:18:11 +03:00
XSendEvent(dpy, w, False, NoEventMask, &e);
XSync(dpy, False);
2005-11-18 18:54:58 +03:00
}
#define NUM_MASKS 8
2005-12-21 18:18:11 +03:00
void
wmii_init_lock_modifiers(Display * dpy, unsigned int *valid_mask,
unsigned int *num_lock_mask)
2005-11-18 18:54:58 +03:00
{
2005-12-21 18:18:11 +03:00
XModifierKeymap *modmap;
KeyCode num_lock;
static int masks[NUM_MASKS] = {
ShiftMask, LockMask, ControlMask, Mod1Mask,
Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
};
int i;
2005-11-18 18:54:58 +03:00
2005-12-21 18:18:11 +03:00
*num_lock_mask = 0;
modmap = XGetModifierMapping(dpy);
num_lock = XKeysymToKeycode(dpy, XStringToKeysym("Num_Lock"));
2005-11-18 18:54:58 +03:00
2005-12-21 18:18:11 +03:00
if(modmap && modmap->max_keypermod > 0) {
int max = NUM_MASKS * modmap->max_keypermod;
for(i = 0; i < max; i++) {
if(num_lock && (modmap->modifiermap[i] == num_lock)) {
*num_lock_mask = masks[i / modmap->max_keypermod];
}
}
}
XFreeModifiermap(modmap);
2005-11-18 18:54:58 +03:00
2005-12-21 18:18:11 +03:00
*valid_mask = 255 & ~(*num_lock_mask | LockMask);
2005-11-18 18:54:58 +03:00
}