Update Serbian translation from master branch
[wmaker-crm.git] / wmlib / event.c
blobceb5ae9b575cbd58b417c05b9e130ac297c318c1
1 /* event.c - WindowMaker event handler
3 * WMlib - WindowMaker application programming interface
5 * Copyright (C) 1997-2003 Alfredo K. Kojima
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
20 * MA 02110-1301, USA.
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <X11/Xlib.h>
26 #include <X11/Xutil.h>
28 #include "WMaker.h"
29 #include "app.h"
30 #include "menu.h"
32 static Atom _XA_WINDOWMAKER_MENU = 0;
34 enum {
35 wmSelectItem = 1
38 static wmMenuEntry *findEntry(WMMenu * menu, int tag)
40 wmMenuEntry *entry = menu->first;
42 while (entry) {
43 if (entry->tag == tag) {
44 return entry;
46 if (entry->cascade) {
47 wmMenuEntry *tmp;
48 tmp = findEntry(entry->cascade, tag);
49 if (tmp)
50 return tmp;
52 entry = entry->next;
54 return NULL;
57 static void wmHandleMenuEvents(WMAppContext * app, XEvent * event)
59 wmMenuEntry *entry;
61 switch (event->xclient.data.l[1]) {
62 case wmSelectItem:
63 entry = findEntry(app->main_menu, event->xclient.data.l[2]);
64 if (entry && entry->callback) {
65 (*entry->callback) (entry->clientData, event->xclient.data.l[2], event->xclient.data.l[0]);
67 break;
71 int WMProcessEvent(WMAppContext * app, XEvent * event)
73 int proc = False;
74 if (!_XA_WINDOWMAKER_MENU) {
75 _XA_WINDOWMAKER_MENU = XInternAtom(app->dpy, "_WINDOWMAKER_MENU", False);
77 switch (event->type) {
78 case ClientMessage:
79 if (event->xclient.format == 32
80 && event->xclient.message_type == _XA_WINDOWMAKER_MENU
81 && event->xclient.window == app->main_window) {
82 wmHandleMenuEvents(app, event);
83 proc = True;
86 return proc;