2 * common/xutil.c - X-related useful functions
4 * Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <X11/Xutil.h>
23 #include <X11/Xatom.h>
25 #include "common/util.h"
26 #include "common/xutil.h"
29 xgettextprop(Display
*disp
, Window w
, Atom atom
, char *text
, ssize_t textlen
)
39 XGetTextProperty(disp
, w
, &name
, atom
);
44 if(name
.encoding
== XA_STRING
)
45 a_strncpy(text
, textlen
, (char *) name
.value
, textlen
- 1);
47 else if(XmbTextPropertyToTextList(disp
, &name
, &list
, &n
) >= Success
&& n
> 0 && *list
)
49 a_strncpy(text
, textlen
, *list
, textlen
- 1);
50 XFreeStringList(list
);
53 text
[textlen
- 1] = '\0';
60 get_numlockmask(Display
*disp
)
62 XModifierKeymap
*modmap
;
63 unsigned int mask
= 0;
66 modmap
= XGetModifierMapping(disp
);
67 for(i
= 0; i
< 8; i
++)
68 for(j
= 0; j
< modmap
->max_keypermod
; j
++)
69 if(modmap
->modifiermap
[i
* modmap
->max_keypermod
+ j
]
70 == XKeysymToKeycode(disp
, XK_Num_Lock
))
73 XFreeModifiermap(modmap
);
78 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80