Change to the linux kernel coding style
[wmaker-crm.git] / wmlib / event.c
Commit [+]AuthorDateLineData
9d2e6ef9 scottc1998-09-29 22:36:29 +00001/* event.c - WindowMaker event handler
6830b057 dan2004-10-12 21:28:27 +00002 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00003 * WMlib - WindowMaker application programming interface
6830b057 dan2004-10-12 21:28:27 +00004 *
4153e2fd dan2003-01-16 23:30:45 +00005 * Copyright (C) 1997-2003 Alfredo K. Kojima
6830b057 dan2004-10-12 21:28:27 +00006 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00007 * 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.
6830b057 dan2004-10-12 21:28:27 +000011 *
9d2e6ef9 scottc1998-09-29 22:36:29 +000012 * 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.
6830b057 dan2004-10-12 21:28:27 +000016 *
9d2e6ef9 scottc1998-09-29 22:36:29 +000017 * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include <stdlib.h>
23#include <stdio.h>
24#include <X11/Xlib.h>
25#include <X11/Xutil.h>
26
27#include "WMaker.h"
28#include "app.h"
29#include "menu.h"
30
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020031static Atom _XA_WINDOWMAKER_MENU = 0;
9d2e6ef9 scottc1998-09-29 22:36:29 +000032
33enum {
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020034 wmSelectItem = 1
9d2e6ef9 scottc1998-09-29 22:36:29 +000035};
36
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020037static wmMenuEntry *findEntry(WMMenu * menu, int tag)
9d2e6ef9 scottc1998-09-29 22:36:29 +000038{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020039 wmMenuEntry *entry = menu->first;
9d2e6ef9 scottc1998-09-29 22:36:29 +000040
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020041 while (entry) {
42 if (entry->tag == tag) {
43 return entry;
44 }
45 if (entry->cascade) {
46 wmMenuEntry *tmp;
47 tmp = findEntry(entry->cascade, tag);
48 if (tmp)
49 return tmp;
50 }
51 entry = entry->next;
52 }
53 return NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +000054}
55
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020056static void wmHandleMenuEvents(WMAppContext * app, XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +000057{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020058 wmMenuEntry *entry;
9d2e6ef9 scottc1998-09-29 22:36:29 +000059
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020060 switch (event->xclient.data.l[1]) {
61 case wmSelectItem:
62 entry = findEntry(app->main_menu, event->xclient.data.l[2]);
63 if (entry && entry->callback) {
64 (*entry->callback) (entry->clientData, event->xclient.data.l[2], event->xclient.data.l[0]);
65 }
66 break;
67 }
9d2e6ef9 scottc1998-09-29 22:36:29 +000068}
69
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020070int WMProcessEvent(WMAppContext * app, XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +000071{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020072 int proc = False;
73 if (!_XA_WINDOWMAKER_MENU) {
74 _XA_WINDOWMAKER_MENU = XInternAtom(app->dpy, "_WINDOWMAKER_MENU", False);
75 }
76 switch (event->type) {
77 case ClientMessage:
78 if (event->xclient.format == 32
79 && event->xclient.message_type == _XA_WINDOWMAKER_MENU
80 && event->xclient.window == app->main_window) {
81 wmHandleMenuEvents(app, event);
82 proc = True;
83 }
84 }
85 return proc;
9d2e6ef9 scottc1998-09-29 22:36:29 +000086}