fixed little bug in non-continuous mode for slider
[wmaker-crm.git] / src / wmsound.c
blob4ed1911eca5348207a5c5c02968699f7f4cee93a
1 #include "wconfig.h"
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <X11/X.h>
6 #include <X11/Xlib.h>
7 #include <X11/Xutil.h>
8 #include <X11/Xproto.h>
10 #include "WindowMaker.h"
11 #include "wmsound.h"
13 #ifdef WMSOUND
15 Window soundServer;
16 XEvent sound_event;
18 extern WPreferences wPreferences;
19 extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
21 void
22 wSoundServerGrab(Window wm_win)
24 Window *lstChildren;
25 Window retRoot;
26 Window retParent;
27 int indexCount;
28 u_int numChildren;
29 XClassHint *retHint;
31 if (XQueryTree(dpy, wm_win, &retRoot, &retParent, &lstChildren, &numChildren)) {
32 for (indexCount = 1; indexCount < numChildren; indexCount++) {
33 retHint = XAllocClassHint();
34 if (!retHint) {
35 XFree(lstChildren);
36 return;
39 XGetClassHint (dpy, lstChildren[indexCount], retHint);
40 if (retHint->res_class) {
41 if (strcmp("WMSoundServer", retHint->res_class) == 0) {
42 soundServer = lstChildren[indexCount];
43 XFree(lstChildren);
44 if(retHint) {
45 XFree(retHint);
47 return;
50 XFree(retHint);
51 retHint = 0;
53 XFree(lstChildren);
55 return;
59 void
60 wSoundPlay(long event_sound)
62 if (!soundServer) {
63 wSoundServerGrab(DefaultRootWindow(dpy));
65 if(soundServer!=None && !wPreferences.no_sound) {
66 sound_event.xclient.type = ClientMessage;
67 sound_event.xclient.message_type = _XA_WINDOWMAKER_WM_FUNCTION;
68 sound_event.xclient.format = 32;
69 sound_event.xclient.display = dpy;
70 sound_event.xclient.window = soundServer;
71 sound_event.xclient.data.l[0] = event_sound;
72 if (XSendEvent(dpy, soundServer, False,
73 NoEventMask, &sound_event)==BadWindow) {
74 soundServer = None;
75 return;
76 } else {
77 XFlush(dpy);
82 #endif /* WMSOUND */