Initial revision
[wmaker-crm.git] / src / wmnotify.c
blob788da49d683dc258e6c5f6a42d2f9da2c7f15150
1 /*
2 * WindowMaker external notification support
3 *
4 * Copyright (c) 1998 Peter Bentley (pete@sorted.org)
5 *
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
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 * USA.
22 #include "wconfig.h"
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <X11/X.h>
27 #include <X11/Xlib.h>
28 #include <X11/Xutil.h>
29 #include <X11/Xproto.h>
31 #include "WindowMaker.h"
32 #include "wcore.h"
33 #include "framewin.h"
34 #include "window.h"
35 #include "properties.h"
36 #include "wmnotify.h"
38 #ifdef WMNOTIFY
39 #define DEBUG
40 extern Atom _XA_WINDOWMAKER_NOTIFY;
42 static LinkedList *wNotifyWindows=NULL;
44 typedef struct WNotifyClient
46 Window not_win; /* Id of window to send notify events to */
47 int not_mask; /* Mask of desired notifications */
48 } WNotifyClient;
51 void wNotify( int id, int a1, int a2 )
56 void wNotifyWin( int id, WWindow *wwin )
58 XEvent event;
59 LinkedList *list;
60 WNotifyClient *clnt;
61 int count = 0, mask = WMN_ID_TO_MASK( id );
63 event.xclient.type = ClientMessage;
64 event.xclient.message_type = _XA_WINDOWMAKER_NOTIFY;
65 event.xclient.format = 32;
66 event.xclient.display = dpy;
67 event.xclient.data.l[0] = id;
68 if( wwin )
69 event.xclient.data.l[1] = wwin->client_win; /* XXX */
70 else
71 event.xclient.data.l[1] = 0;
72 event.xclient.data.l[2] = 0;
73 event.xclient.data.l[3] = 0;
75 for( list = wNotifyWindows; list; list = list->tail )
77 clnt = list->head;
78 if( clnt->not_mask & mask )
80 #ifdef DEBUG
81 printf( "Send event %d to 0x%x\n", id, (int) clnt->not_win );
82 #endif
83 event.xclient.window = clnt->not_win;
84 XSendEvent(dpy, clnt->not_win, False, NoEventMask, &event);
85 count++;
88 if( count )
89 XFlush(dpy);
93 int wNotifySet(Window window)
95 int mask;
96 WNotifyClient *clnt;
98 if( PropGetNotifyMask( window, &mask )) {
99 wNotifyClear( window ); /* Remove any current mask */
100 #ifdef DEBUG
101 printf( "Setting notify mask for window 0x%x to 0x%02x\n",
102 (int) window, mask );
103 #endif
104 clnt = wmalloc( sizeof( WNotifyClient ));
105 if( clnt )
107 clnt->not_win = window;
108 clnt->not_mask = mask;
109 wNotifyWindows = list_cons( clnt, wNotifyWindows );
110 return True;
113 return False;
116 int wNotifyClear(Window window)
118 LinkedList *list;
119 WNotifyClient *clnt;
121 for( list = wNotifyWindows; list; list = list->tail )
123 clnt = list->head;
124 if( clnt->not_win == window )
126 #ifdef DEBUG
127 printf( "Clearing notify mask for window 0x%x (was 0x%02x)\n",
128 (int) clnt->not_win, clnt->not_mask );
129 #endif
130 wNotifyWindows = list_remove_elem( wNotifyWindows, clnt );
131 free( clnt );
132 return True;
135 return False;
139 #endif /* WMNOTIFY */