|
Lines 1-6
Link Here
|
| 1 |
/* xxkb - XKB keyboard indicator/switcher */ |
1 |
/* xxkb - XKB keyboard indicator/switcher */ |
| 2 |
/* (c) 1999 - 2003 Ivan Pascal <pascal@tsu.ru> */ |
2 |
/* (c) 1999 - 2003 Ivan Pascal <pascal@tsu.ru> */ |
| 3 |
|
3 |
|
|
|
4 |
#include <stdio.h> |
| 5 |
#include <stdlib.h> |
| 4 |
#include <X11/Xlib.h> |
6 |
#include <X11/Xlib.h> |
| 5 |
#include <X11/Xutil.h> |
7 |
#include <X11/Xutil.h> |
| 6 |
#include <X11/XKBlib.h> |
8 |
#include <X11/XKBlib.h> |
|
Lines 35-43
Link Here
|
| 35 |
WInfo def_info, *info, *tmp_info; |
37 |
WInfo def_info, *info, *tmp_info; |
| 36 |
kbdState def_state; |
38 |
kbdState def_state; |
| 37 |
XFocusChangeEvent focused_event; |
39 |
XFocusChangeEvent focused_event; |
|
|
40 |
|
| 41 |
struct { |
| 42 |
Bool enable; |
| 43 |
Atom tray_atom; |
| 44 |
Atom opcode_atom; |
| 45 |
Atom manager_atom; |
| 46 |
Window manager; |
| 47 |
} gnome2_tray; |
| 48 |
|
| 38 |
XErrorHandler DefErrHandler; |
49 |
XErrorHandler DefErrHandler; |
|
|
50 |
static Bool trap_errors = False; |
| 51 |
static int trapped_error_code = 0; |
| 39 |
|
52 |
|
| 40 |
static ListAction FindAppList(Window w); |
53 |
static ListAction FindAppList(Window w); |
|
|
54 |
static void Gnome2TrayUpdateManager(); |
| 41 |
|
55 |
|
| 42 |
int main (int argc, char ** argv) |
56 |
int main (int argc, char ** argv) |
| 43 |
{ |
57 |
{ |
|
Lines 148-153
Link Here
|
| 148 |
} |
162 |
} |
| 149 |
else icon = (Window) 0; |
163 |
else icon = (Window) 0; |
| 150 |
|
164 |
|
|
|
165 |
gnome2_tray.enable = False; |
| 166 |
|
| 151 |
if (conf.tray_type) { |
167 |
if (conf.tray_type) { |
| 152 |
Atom r; |
168 |
Atom r; |
| 153 |
int data = 1; |
169 |
int data = 1; |
|
Lines 161-178
Link Here
|
| 161 |
r = XInternAtom(dpy, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", False); |
177 |
r = XInternAtom(dpy, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", False); |
| 162 |
XChangeProperty(dpy, MainWin, r, XA_WINDOW, 32, 0, |
178 |
XChangeProperty(dpy, MainWin, r, XA_WINDOW, 32, 0, |
| 163 |
(unsigned char *)&data, 1); |
179 |
(unsigned char *)&data, 1); |
|
|
180 |
} else if (! strcmp(conf.tray_type, "GNOME2")) { |
| 181 |
char tmp[64]; |
| 182 |
|
| 183 |
size_hints = XAllocSizeHints(); |
| 184 |
size_hints->width = size_hints->min_width = geom.width; |
| 185 |
size_hints->height = size_hints->min_height = geom.height; |
| 186 |
size_hints->flags = PSize | PMinSize; |
| 187 |
XSetWMNormalHints(dpy, MainWin, size_hints); |
| 188 |
|
| 189 |
gnome2_tray.enable = True; |
| 190 |
sprintf(tmp, "_NET_SYSTEM_TRAY_S%d", scr); |
| 191 |
gnome2_tray.tray_atom = XInternAtom(dpy, tmp, False); |
| 192 |
gnome2_tray.opcode_atom = XInternAtom(dpy, |
| 193 |
"_NET_SYSTEM_TRAY_OPCODE", False); |
| 194 |
gnome2_tray.manager_atom = XInternAtom(dpy, "MANAGER", False); |
| 164 |
} |
195 |
} |
| 165 |
} |
196 |
} |
|
|
197 |
|
| 166 |
|
198 |
|
| 167 |
|
199 |
|
| 168 |
|
200 |
if (conf.controls&Main_enable && ! gnome2_tray.enable) |
| 169 |
if (conf.controls&Main_enable) XMapWindow(dpy, MainWin); |
201 |
XMapWindow(dpy, MainWin); |
| 170 |
|
202 |
|
| 171 |
/* What events we want */ |
203 |
/* What events we want */ |
| 172 |
XkbSelectEventDetails(dpy, XkbUseCoreKbd, XkbStateNotify, |
204 |
XkbSelectEventDetails(dpy, XkbUseCoreKbd, XkbStateNotify, |
| 173 |
XkbAllStateComponentsMask, XkbGroupStateMask); |
205 |
XkbAllStateComponentsMask, XkbGroupStateMask); |
| 174 |
if (conf.controls&When_create) |
206 |
XSelectInput(dpy, root, |
| 175 |
XSelectInput(dpy, root, SubstructureNotifyMask); |
207 |
((conf.controls&When_create) ? SubstructureNotifyMask : NoEventMask) | |
|
|
208 |
((gnome2_tray.enable) ? StructureNotifyMask : NoEventMask)); |
| 176 |
|
209 |
|
| 177 |
XSelectInput(dpy, MainWin, ExposureMask | ButtonPressMask); |
210 |
XSelectInput(dpy, MainWin, ExposureMask | ButtonPressMask); |
| 178 |
if (icon) XSelectInput(dpy, icon, ExposureMask | ButtonPressMask); |
211 |
if (icon) XSelectInput(dpy, icon, ExposureMask | ButtonPressMask); |
|
Lines 205-210
Link Here
|
| 205 |
if (!info) info = &def_info; |
238 |
if (!info) info = &def_info; |
| 206 |
} |
239 |
} |
| 207 |
|
240 |
|
|
|
241 |
if (gnome2_tray.enable) Gnome2TrayUpdateManager(); |
| 242 |
|
| 208 |
/* Main Loop */ |
243 |
/* Main Loop */ |
| 209 |
while (1) { |
244 |
while (1) { |
| 210 |
XNextEvent(dpy, &ev.core); |
245 |
XNextEvent(dpy, &ev.core); |
|
Lines 391-396
Link Here
|
| 391 |
if(((win == MainWin) || (win == icon)) |
426 |
if(((win == MainWin) || (win == icon)) |
| 392 |
&& ev.core.xclient.data.l[0] == wm_del_win) |
427 |
&& ev.core.xclient.data.l[0] == wm_del_win) |
| 393 |
Terminate(); |
428 |
Terminate(); |
|
|
429 |
else if (gnome2_tray.enable && |
| 430 |
ev.core.xclient.message_type == gnome2_tray.manager_atom && |
| 431 |
ev.core.xclient.data.l[1] == gnome2_tray.tray_atom) |
| 432 |
Gnome2TrayUpdateManager(); |
| 394 |
break; |
433 |
break; |
| 395 |
case CreateNotify: |
434 |
case CreateNotify: |
| 396 |
case UnmapNotify: |
435 |
case UnmapNotify: |
|
Lines 758-766
Link Here
|
| 758 |
} |
797 |
} |
| 759 |
} |
798 |
} |
| 760 |
|
799 |
|
| 761 |
void ErrHandler(Display *dpy, XErrorEvent* err) |
800 |
static void Gnome2TrayUpdateManager() |
| 762 |
{ |
801 |
{ |
| 763 |
if((err->error_code == BadWindow) || (err->error_code == BadDrawable)) |
802 |
gnome2_tray.manager = XGetSelectionOwner(dpy, |
| 764 |
return; |
803 |
gnome2_tray.tray_atom); |
| 765 |
(*DefErrHandler)(dpy, err); |
804 |
|
|
|
805 |
if (gnome2_tray.manager) |
| 806 |
{ |
| 807 |
XClientMessageEvent xev; |
| 808 |
memset(&xev, 0, sizeof(xev)); |
| 809 |
xev.type = ClientMessage; |
| 810 |
xev.window = gnome2_tray.manager; |
| 811 |
xev.message_type = gnome2_tray.opcode_atom; |
| 812 |
xev.format = 32; |
| 813 |
xev.data.l[0] = CurrentTime; |
| 814 |
xev.data.l[1] = 0; /* SYSTEM_TRAY_REQUEST_DOCK */ |
| 815 |
xev.data.l[2] = MainWin; |
| 816 |
|
| 817 |
TrapErrors(); |
| 818 |
XSendEvent(dpy, gnome2_tray.manager, False, NoEventMask, |
| 819 |
(XEvent *) &xev); |
| 820 |
UntrapErrors(); |
| 821 |
} |
| 822 |
} |
| 823 |
|
| 824 |
void TrapErrors() |
| 825 |
{ |
| 826 |
trapped_error_code = 0; |
| 827 |
trap_errors = True; |
| 828 |
} |
| 829 |
|
| 830 |
int UntrapErrors() |
| 831 |
{ |
| 832 |
trap_errors = False; |
| 833 |
return trapped_error_code; |
| 834 |
} |
| 835 |
|
| 836 |
int ErrHandler(Display *dpy, XErrorEvent* err) |
| 837 |
{ |
| 838 |
if (! trap_errors) { |
| 839 |
if((err->error_code == BadWindow) || (err->error_code == BadDrawable)) |
| 840 |
return 0; |
| 841 |
(*DefErrHandler)(dpy, err); |
| 842 |
} else { |
| 843 |
trapped_error_code = err->error_code; |
| 844 |
return 0; |
| 845 |
} |
| 766 |
} |
846 |
} |