d14861e867daac86ace84096f031d953ef2c7d5c
[uwplayer.git] / application / window.c
1 /*
2  * Copyright 2022 Olaf Wintermann
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a 
5  * copy of this software and associated documentation files (the "Software"), 
6  * to deal in the Software without restriction, including without limitation 
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
8  * and/or sell copies of the Software, and to permit persons to whom the 
9  * Software is furnished to do so, subject to the following conditions:
10  * 
11  * The above copyright notice and this permission notice shall be included in 
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
20  * DEALINGS IN THE SOFTWARE.
21  */
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26
27 #include "window.h"
28 #include "main.h"
29 #include "player.h"
30
31 #include "Fsb.h"
32
33 static MainWindow *main_window;
34
35 static void WindowCreateMenu(MainWindow *win, Widget parent, Arg *args, int nargs);
36
37 static void FileOpenCB(Widget w, void *udata, void *cdata);
38 static void FileQuitCB(Widget w, void *udata, void *cdata);
39 static void PlayRepeatCB(Widget w, void *udata, void *cdata);
40 static void PlayRepeatListCB(Widget w, void *udata, void *cdata);
41 static void PlayAutoPlayCB(Widget w, void *udata, void *cdata);
42 static void ViewFullscreenCB(Widget w, void *udata, void *cdata);
43
44 static void WindowRealized(MainWindow *win);
45
46 static int blank_cursor_init = 0;
47 static Pixmap blank_cursor_pixmap;
48 static Cursor blank_cursor;
49
50 static void init_blank_cursor(Widget w) {
51     char data = 0;
52     
53     XColor c;
54     
55     blank_cursor_pixmap = XCreateBitmapFromData(XtDisplay(w), XtWindow(w), &data, 1, 1);
56     if(!blank_cursor_pixmap) return;
57     
58     blank_cursor = XCreatePixmapCursor(XtDisplay(w), blank_cursor_pixmap, blank_cursor_pixmap, &c, &c, 0, 0);
59     
60     XFreePixmap(XtDisplay(w), blank_cursor_pixmap);
61     blank_cursor_init = 1;
62 }
63
64 static void window_close_handler(Widget window, void *udata, void *cdata) {
65     FileQuitCB(window, NULL, NULL);
66 }
67
68 static unsigned int keycodeF;
69
70 static void windowKeyEH(Widget widget, XtPointer data, XEvent *event, Boolean *dispatch) {
71     MainWindow *win = data;
72     if(win->fullscreen && event->xkey.keycode == keycodeF) {
73         WindowFullscreen(main_window, FALSE);
74         *dispatch = FALSE;
75     }
76 }
77
78 static int main_window_is_realized = 0;
79
80 static void resizeEH(Widget widget, XtPointer data, XEvent *event, Boolean *dispatch) {  
81     if(!main_window_is_realized) {
82         if(XtIsRealized(widget)) {
83             main_window_is_realized = 1;
84             WindowRealized(data);
85         }
86     }
87     WindowAdjustAspectRatio(data);
88 }
89
90 static void WindowRealized(MainWindow *win) {
91     char *open_file = GetOpenFileArg();
92     if(open_file) {
93         size_t len = strlen(open_file);
94         char *file = XtMalloc(len+1);
95         memcpy(file, open_file, len);
96         file[len] = 0;
97         WindowSetFile(win, file);
98         PlayerOpenFile(win);
99         CleanOpenFileArg();
100     }
101     
102     if(!blank_cursor_init) {
103         init_blank_cursor(win->player_widget);
104     }
105 }
106
107 static void playerWidgetInputCB(Widget widget, XtPointer u, XtPointer c) {
108     MainWindow *win = u;
109     XmDrawingAreaCallbackStruct *cb = c;
110     
111     if(win->player && win->player->isactive) {
112         PlayerHandleInput(win, win->player, cb);
113     }
114 }
115
116 static void windowGrabButton(MainWindow *win) {
117     //printf("grab\n");
118     XtGrabButton(
119                 win->player_widget,
120                 AnyButton,
121                 AnyModifier,
122                 True,
123                 ButtonPressMask | ButtonReleaseMask | PointerMotionMask | FocusChangeMask | EnterWindowMask | LeaveWindowMask,
124                 GrabModeAsync,
125                 GrabModeAsync,
126                 None,
127                 None);
128     win->buttongrab = True;
129 }
130
131 static void playerEH(Widget widget, XtPointer data, XEvent *event, Boolean *dispatch) {
132     MainWindow *win = data;
133     int etype = event->type;
134     
135     ///*
136     if(etype == EnterNotify) {
137         //printf("enter\n");
138         windowGrabButton(win);
139         return;
140     }
141     if(etype == LeaveNotify) {
142         //printf("leave\n");
143         //XtUngrabButton(win->player_widget, AnyButton, AnyModifier); 
144         //win->buttongrab = False;
145         return;
146     }
147     
148     int pass = 0;
149     if(etype == ButtonPress || etype == ButtonRelease || etype == KeyPress || etype == KeyRelease) {
150         //printf("button press\n");
151         pass = 1;
152     }
153     
154     if(!win->player || win->player->window == 0) return;
155     
156     WindowHandlePlayerEvent(win, event);
157     
158     if(pass) {
159         // redirect key events to the player window
160         //printf("redirect\n");
161         event->xkey.window = win->player->window;
162         XSendEvent(
163                 XtDisplay(win->player_widget),
164                 win->player->window,
165                 True,
166                 0,
167                 event);
168     }
169 }
170
171 #define IGNORE_MOTION_THRESHOLD_MS 1000
172 #define MOTION_POS_THRESHOLD_PIX   5
173
174 #define DOUBLE_CLICK_TIME_MS       500
175
176 void WindowHandlePlayerEvent(MainWindow *win, XEvent *event) {
177     // event handler for intercepted player mouse events
178     // win->player is not NULL
179     
180     int etype = event->type;
181     
182     if(etype == MotionNotify) {
183         Time cur_motion_time = event->xmotion.time;
184         int x = event->xmotion.x;
185         int y = event->xmotion.y;
186         if(win->cursorhidden && cur_motion_time - win->player_event_time < IGNORE_MOTION_THRESHOLD_MS) {
187             int diff_x = abs(x - win->mouse_x_orig);
188             int diff_y = abs(y - win->mouse_y_orig);
189             if(diff_x > MOTION_POS_THRESHOLD_PIX || diff_y > MOTION_POS_THRESHOLD_PIX) {
190                 WindowShowPlayerCursor(win);
191             }
192         } else {
193             win->mouse_x_orig = x;
194             win->mouse_y_orig = y;
195         }
196         win->player_event_time = cur_motion_time;
197         win->motion_playback_time = win->player->playback_time;
198     } else if(etype == ButtonPress) {
199         Time t = event->xbutton.time;
200         if(t - win->button_press_time < DOUBLE_CLICK_TIME_MS) {
201             // double click
202             WindowFullscreen(main_window, !win->fullscreen);
203             win->button_press_time = 0;
204         } else {
205             win->button_press_time = t;
206         }
207     } else if(etype == ButtonRelease) {
208         win->player_event_time = event->xbutton.time;
209     }
210 }
211
212 MainWindow* WindowCreate(Display *display) {
213     Arg args[32];
214     int n;
215      
216     MainWindow *window = malloc(sizeof(MainWindow));
217     memset(window, 0, sizeof(MainWindow));
218     main_window = window;
219     
220     // toplevel window
221     n = 0;
222     XtSetArg(args[n], XmNtitle, APP_NAME); n++;
223     window->window = XtAppCreateShell(
224             APP_NAME,
225             APP_CLASS,
226             applicationShellWidgetClass,
227             //vendorShellWidgetClass,
228             display,
229             args,
230             n);
231     
232     // close handler
233     Atom wm_delete_window;
234     wm_delete_window = XmInternAtom(
235             display,
236             "WM_DELETE_WINDOW",
237             0);
238     XmAddWMProtocolCallback(
239             window->window,
240             wm_delete_window,
241             window_close_handler,
242             window);
243     
244     // resize handler
245     XtAddEventHandler(window->window, StructureNotifyMask, False, resizeEH, window);
246     
247     n = 0;
248     XtSetArg(args[n], XmNwidth, 360); n++;
249     XtSetArg(args[n], XmNheight, 220); n++;
250     XtSetArg(args[n], XmNshadowThickness, 0); n++;
251     Widget container = XmCreateForm(window->window, "form", args, n);
252     XtManageChild(container);
253     XtAddEventHandler(container, KeyPressMask, FALSE, windowKeyEH, window);
254     
255     n = 0;
256     XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
257     XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
258     XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
259     WindowCreateMenu(window, container, args, n);
260     
261     n = 0;
262     XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
263     XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
264     XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
265     XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
266     XtSetArg(args[n], XmNtopWidget, window->menubar); n++;
267     XtSetArg(args[n], XmNbackground, BlackPixelOfScreen(XtScreen(window->window))); n++;
268     window->player_widget = XmCreateDrawingArea(container, "player", args, n);
269     XtManageChild(window->player_widget);
270     XtAddCallback(window->player_widget, XmNinputCallback, playerWidgetInputCB, window);
271     XmProcessTraversal(window->player_widget, XmTRAVERSE_CURRENT);
272     XtAddEventHandler(window->player_widget, PointerMotionMask | ButtonPressMask | ButtonReleaseMask | FocusChangeMask |
273                  EnterWindowMask | KeyPressMask | KeyReleaseMask |
274                   LeaveWindowMask, FALSE, playerEH, window);
275     
276     
277     // get F keycode
278     keycodeF = XKeysymToKeycode(XtDisplay(window->window), XStringToKeysym("F"));
279     
280     return window;
281 }
282
283 MainWindow* GetMainWindow(void) {
284     return main_window;
285 }
286
287 void WindowShow(MainWindow *win) {
288     XtRealizeWidget(win->window);
289 }
290
291 /*
292  * Creates a XmPushButton menu item
293  */
294 static Widget createMenuItem(
295         Widget menu,
296         char *name,
297         char *label,
298         char mnemonic,
299         const char *accelerator,
300         char *accelerator_text,
301         XtCallbackProc callback,
302         void *cbData)
303 {
304     Arg args[16];
305     int n = 0;
306     
307     XmString s1 = XmStringCreateSimple(label);
308     XtSetArg(args[n], XmNlabelString, s1); n++;
309     XtSetArg(args[n], XmNmnemonic, mnemonic); n++;
310     XmString at = NULL;
311     if(accelerator && accelerator_text) {
312         at = XmStringCreateSimple(accelerator_text);
313         XtSetArg(args[n], XmNaccelerator, accelerator); n++;
314         XtSetArg(args[n], XmNacceleratorText, at); n++;
315     }
316     
317     Widget menuItem = XmCreatePushButtonGadget(menu, name, args, n);
318     XtManageChild(menuItem);
319     XmStringFree(s1);
320     if(at) XmStringFree(at);
321     
322     if(callback) {
323         XtAddCallback(menuItem, XmNactivateCallback, (XtCallbackProc)callback, cbData);
324     }
325     
326     return menuItem;
327 }
328
329 /*
330  * Creates a XmToggleButton menu item
331  */
332 static Widget createToggleMenuItem(
333         Widget menu,
334         char *name,
335         char *label,
336         char mnemonic,
337         Boolean defaultValue,
338         const char *accelerator,
339         char *accelerator_text,
340         XtCallbackProc callback,
341         void *cbData)
342 {
343     Arg args[16];
344     int n = 0;
345     
346     XmString s1 = XmStringCreateSimple(label);
347     XtSetArg(args[n], XmNlabelString, s1); n++;
348     XtSetArg(args[n], XmNmnemonic, mnemonic); n++;
349     XtSetArg(args[n], XmNset, defaultValue); n++;
350     XmString at = NULL;
351     if(accelerator && accelerator_text) {
352         at = XmStringCreateSimple(accelerator_text);
353         XtSetArg(args[n], XmNaccelerator, accelerator); n++;
354         XtSetArg(args[n], XmNacceleratorText, at); n++;
355     }
356     
357     Widget menuItem = XmCreateToggleButtonGadget(menu, name, args, n);
358     XtManageChild(menuItem);
359     XmStringFree(s1);
360     if(at) XmStringFree(at);
361     
362     if(callback) {
363         XtAddCallback(menuItem, XmNvalueChangedCallback, (XtCallbackProc)callback, cbData);
364     }
365     
366     return menuItem;
367 }
368
369 static void WindowCreateMenu(MainWindow *win, Widget parent, Arg *mbargs, int nmbargs) {
370     Widget menubar = XmCreateMenuBar(parent, "menubar", mbargs, nmbargs);
371     XtManageChild(menubar);
372     win->menubar = menubar;
373     
374     Arg args[16];
375     int n;
376     
377     // menus
378     XmString s = XmStringCreateSimple("File");
379     XtVaCreateManagedWidget(
380             "menuitem",
381             xmCascadeButtonWidgetClass,
382             menubar,
383             XmNlabelString, s,
384             NULL);
385     XmStringFree(s);
386     Widget fileMenu = XmVaCreateSimplePulldownMenu(menubar, "menu", 0, NULL, NULL);
387     
388     s = XmStringCreateSimple("Playback");
389     XtVaCreateManagedWidget(
390             "menuitem",
391             xmCascadeButtonWidgetClass,
392             menubar,
393             XmNlabelString, s,
394             NULL);
395     XmStringFree(s);
396     Widget playMenu = XmVaCreateSimplePulldownMenu(menubar, "menu", 1, NULL, NULL);
397     
398     s = XmStringCreateSimple("View");
399     Widget viewMenuItem = XtVaCreateManagedWidget(
400             "menuitem",
401             xmCascadeButtonWidgetClass,
402             menubar,
403             XmNlabelString, s,
404             NULL);
405     XmStringFree(s);
406     Widget viewMenu = XmVaCreateSimplePulldownMenu(menubar, "menu", 2, NULL, NULL);
407     
408     // file menu
409     createMenuItem(fileMenu, "fileOpen", "Open...", 'O', "Ctrl<Key>O", "Ctrl+O", FileOpenCB, NULL);
410     createMenuItem(fileMenu, "fileQuit", "Exit", 'E', "Ctrl<Key>Q", "Ctrl+Q", FileQuitCB, NULL);
411     
412     // play menu
413     win->playRepeatTrackButton = createToggleMenuItem(playMenu, "playRepeatTrack", "Repeat", 'R', False, NULL, NULL, PlayRepeatCB, win);
414     win->playRepeatListButton = createToggleMenuItem(playMenu, "playRepeatList", "Repeat List", 'L', False, NULL, NULL, PlayRepeatListCB, win);
415     win->playAutoPlayButton = createToggleMenuItem(playMenu, "playAutoNext", "Autoplay Folder", 'A', False, NULL, NULL, PlayAutoPlayCB, win);
416     XtVaSetValues(win->playRepeatTrackButton, XmNindicatorType, XmONE_OF_MANY, NULL);
417     XtVaSetValues(win->playRepeatListButton, XmNindicatorType, XmONE_OF_MANY, NULL);
418     XtVaSetValues(win->playAutoPlayButton, XmNindicatorType, XmONE_OF_MANY, NULL);
419     
420     // view menu
421     createMenuItem(viewMenu, "viewFullscreen", "Fullscreen", 'F', "<Key>F", "F", ViewFullscreenCB, NULL);
422 }
423
424 void go_fullscreen(Display *dsp, Window win)
425 {
426   XEvent xev;
427   Atom wm_state = XInternAtom(dsp, "_NET_WM_STATE", False);
428   Atom fullscreen = XInternAtom(dsp, "_NET_WM_STATE_FULLSCREEN", False);
429   memset(&xev, 0, sizeof(xev));
430   xev.type = ClientMessage;
431   xev.xclient.window = win;
432   xev.xclient.message_type = wm_state;
433   xev.xclient.format = 32;
434   xev.xclient.data.l[0] = 1; // _NET_WM_STATE_ADD
435   xev.xclient.data.l[1] = fullscreen;
436   xev.xclient.data.l[2] = 0;
437   XSendEvent(dsp, DefaultRootWindow(dsp), False,
438     SubstructureNotifyMask, &xev);
439 }
440
441 static Atom net_wm_state;
442 static Atom net_wm_state_fullscreen;
443 static int net_wm_atoms_initialized = 0;
444
445 void WindowFullscreen(MainWindow *win, bool enableFullscreen) {
446     Display *dpy = XtDisplay(win->window);
447     
448     // init net_wm_state atoms
449     if(!net_wm_atoms_initialized) {
450         net_wm_state = XInternAtom(dpy, "_NET_WM_STATE", False);
451         net_wm_state_fullscreen = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False);
452         net_wm_atoms_initialized = 1;
453     }
454     
455     WindowMenubarSetVisible(win, !enableFullscreen);
456     if(enableFullscreen && !win->fullscreen) {
457         XtUnmanageChild(main_window->menubar);
458         main_window->fullscreen = TRUE;
459     } else if(!enableFullscreen && win->fullscreen) {
460         XtManageChild(main_window->menubar);
461         main_window->fullscreen = FALSE;
462     }
463     
464     XEvent ev;
465     memset(&ev, 0, sizeof(XEvent));
466     ev.type = ClientMessage;
467     ev.xclient.window = XtWindow(win->window);
468     ev.xclient.message_type = net_wm_state;
469     ev.xclient.format = 32;
470     ev.xclient.data.l[0] = enableFullscreen ? 1 : 0;
471     ev.xclient.data.l[1] = net_wm_state_fullscreen;
472     ev.xclient.data.l[2] = 0;
473     XSendEvent(dpy, DefaultRootWindow(dpy), False, SubstructureNotifyMask | SubstructureRedirectMask, &ev);
474 }
475
476 void WindowMenubarSetVisible(MainWindow *win, bool visible) {
477     if(visible) {
478         XtManageChild(main_window->menubar);
479         XtVaSetValues(main_window->player_widget, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, main_window->menubar, NULL);
480     } else {
481         XtUnmanageChild(main_window->menubar);
482         XtVaSetValues(main_window->player_widget, XmNtopAttachment, XmATTACH_FORM, NULL);
483     }
484 }
485
486 void WindowSetFile(MainWindow *win, char *file) {
487     if(win->file) {
488         XtFree(win->file);
489     }
490     win->file = file;
491 }
492
493 static void filedialog_end(
494         Widget widget,
495         MainWindow *data,
496         XmFileSelectionBoxCallbackStruct *selection)
497 {
498     XtUnmanageChild(widget);
499     XtDestroyWidget(widget);
500 }
501
502 static void filedialog_select(
503         Widget widget,
504         MainWindow *data,
505         XmFileSelectionBoxCallbackStruct *selection)
506 {
507     char *value = NULL;
508     if(selection->value) {
509         XmStringGetLtoR(selection->value, XmSTRING_DEFAULT_CHARSET, &value);
510         if(value) {
511             WindowSetFile(data, value);
512             // no need to free the value, because it is stored in MainWindow
513             
514             PlayerOpenFile(data);
515         }
516     }
517     filedialog_end(widget, data, NULL);
518 }
519
520
521
522
523 static void FileOpenCB(Widget w, void *udata, void *cdata) {
524     MainWindow *win = main_window;
525     
526     Arg args[16];
527     int n = 0;
528     
529     XtSetArg(args[n], XnNshowViewMenu, 1); n++;
530     Widget dialog = XnCreateFileSelectionDialog(win->window, "dialog", args, n);
531     XtAddCallback(dialog, XmNokCallback, (XtCallbackProc)filedialog_select, win);
532     XtAddCallback(dialog, XmNcancelCallback, (XtCallbackProc)filedialog_end, win);
533     
534     Widget dirUp = XnFileSelectionBoxGetChild(dialog, XnFSB_DIR_UP_BUTTON);
535     XtUnmanageChild(dirUp);
536     
537     XtManageChild(dialog);
538 }
539
540 static void FileQuitCB(Widget w, void *udata, void *cdata) {
541     WindowClosePlayer(main_window);
542     ApplicationExit();
543 }
544
545 static void PlayRepeatCB(Widget w, void *udata, void *cdata) {
546     MainWindow *win = udata;
547     win->repeatTrack = XmToggleButtonGadgetGetState(w);
548     win->repeatList = 0;
549     win->autoplayFolder = 0;
550     XtVaSetValues(win->playRepeatListButton, XmNset, 0, NULL);
551     XtVaSetValues(win->playAutoPlayButton, XmNset, 0, NULL);
552 }
553
554 static void PlayRepeatListCB(Widget w, void *udata, void *cdata) {
555     MainWindow *win = udata;
556     win->repeatList = XmToggleButtonGadgetGetState(w);
557     win->repeatTrack = 0;
558     win->autoplayFolder = 0;
559     XtVaSetValues(win->playRepeatTrackButton, XmNset, 0, NULL);
560     XtVaSetValues(win->playAutoPlayButton, XmNset, 0, NULL);
561 }
562
563 static void PlayAutoPlayCB(Widget w, void *udata, void *cdata) {
564     MainWindow *win = udata;
565     win->autoplayFolder = XmToggleButtonGadgetGetState(w);
566     win->repeatTrack = 0;
567     win->repeatList = 0;
568     XtVaSetValues(win->playRepeatTrackButton, XmNset, 0, NULL);
569     XtVaSetValues(win->playRepeatListButton, XmNset, 0, NULL);
570 }
571
572 static void ViewFullscreenCB(Widget w, void *udata, void *cdata) {
573     if(main_window->fullscreen) {
574         WindowFullscreen(main_window, FALSE);
575     } else {
576         WindowFullscreen(main_window, TRUE);
577     }
578     
579 }
580
581 void WindowAdjustAspectRatio(MainWindow *win) {
582     if(!win->player) return;
583     if(!win->player->isactive || win->player->width <= 0 || win->player->height <= 0) return;
584       
585     // we have a running player width video
586     // adjust window aspect ratio (the window aspect ratio is different from
587     // the video, because of window decoration, menubar and other extra controls)
588     
589     Dimension win_width, win_height;
590     XtVaGetValues(win->window, XmNwidth, &win_width, XmNheight, &win_height, NULL);
591     Dimension player_width, player_height;
592     XtVaGetValues(win->player_widget, XmNwidth, &player_width, XmNheight, &player_height, NULL);
593     
594     double r = (double)win->player->width / (double)win->player->height;
595     double p_width = player_width;
596     double p_height = p_width / r;
597     
598     Dimension new_width = p_width + win_width - player_width;
599     Dimension new_height = p_height + win_height - player_height;
600     
601     XSizeHints hints;
602     hints.flags = PAspect;
603     hints.min_aspect.x = new_width;
604     hints.min_aspect.y = new_height;
605     hints.max_aspect.x = new_width;
606     hints.max_aspect.y = new_height;
607     XSetWMNormalHints(XtDisplay(win->window), XtWindow(win->window), &hints);
608 }
609
610 void WindowClosePlayer(MainWindow *win) {
611     if(win->player) {
612         PlayerDestroy(win->player);
613     }
614     win->player = NULL;
615     WindowShowPlayerCursor(win);
616 }
617
618 void WindowHidePlayerCursor(MainWindow *win) {
619     if(!win->cursorhidden && win->player && win->player->window != 0) {
620         XDefineCursor(XtDisplay(win->player_widget), XtWindow(win->player_widget), blank_cursor);
621         win->cursorhidden = True;
622         XFlush(XtDisplay(win->player_widget));
623     }
624 }
625
626 void WindowShowPlayerCursor(MainWindow *win) {
627     if(win->cursorhidden && win->player && win->player->window != 0) {
628         XDefineCursor(XtDisplay(win->player_widget), XtWindow(win->player_widget), None);
629         XFlush(XtDisplay(win->player_widget));
630     }
631     win->cursorhidden = False;
632 }