From: Olaf Wintermann Date: Sun, 16 Jan 2022 14:19:40 +0000 (+0100) Subject: add repeat toggle button X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=b4c8e61d4466789fddccac524f046f038d86d681;p=uwplayer.git add repeat toggle button --- diff --git a/application/player.c b/application/player.c index 4764e98..4d0ef22 100644 --- a/application/player.c +++ b/application/player.c @@ -561,8 +561,11 @@ static void json_print(JSONValue *value, char *name, int indent) { } void PlayerEOF(Player *p) { - char *cmd = "{ \"command\": [\"set_property\", \"playback-time\", 0] }\n"; - write(p->ipc, cmd, strlen(cmd)); + MainWindow *win = GetMainWindow(); + if(win->repeatTrack) { + char *cmd = "{ \"command\": [\"set_property\", \"playback-time\", 0] }\n"; + write(p->ipc, cmd, strlen(cmd)); + } } void PlayerHandleInput(MainWindow *win, Player *p, XmDrawingAreaCallbackStruct *cb) { diff --git a/application/window.c b/application/window.c index 17bda64..b0d9a34 100644 --- a/application/window.c +++ b/application/window.c @@ -35,6 +35,8 @@ static MainWindow *main_window; static void WindowCreateMenu(MainWindow *win, Widget parent, Arg *args, int nargs); static void FileOpenCB(Widget w, void *udata, void *cdata); +static void FileQuitCB(Widget w, void *udata, void *cdata); +static void PlayRepeatCB(Widget w, void *udata, void *cdata); static void ViewFullscreenCB(Widget w, void *udata, void *cdata); static void WindowRealized(MainWindow *win); @@ -58,8 +60,7 @@ static void init_blank_cursor(Widget w) { } static void window_close_handler(Widget window, void *udata, void *cdata) { - WindowClosePlayer(main_window); - ApplicationExit(); + FileQuitCB(window, NULL, NULL); } static unsigned int keycodeF; @@ -323,6 +324,46 @@ static Widget createMenuItem( return menuItem; } +/* + * Creates a XmToggleButton menu item + */ +static Widget createToggleMenuItem( + Widget menu, + char *name, + char *label, + char mnemonic, + Boolean defaultValue, + const char *accelerator, + char *accelerator_text, + XtCallbackProc callback, + void *cbData) +{ + Arg args[16]; + int n = 0; + + XmString s1 = XmStringCreateSimple(label); + XtSetArg(args[n], XmNlabelString, s1); n++; + XtSetArg(args[n], XmNmnemonic, mnemonic); n++; + XtSetArg(args[n], XmNset, defaultValue); n++; + XmString at = NULL; + if(accelerator && accelerator_text) { + at = XmStringCreateSimple(accelerator_text); + XtSetArg(args[n], XmNaccelerator, accelerator); n++; + XtSetArg(args[n], XmNacceleratorText, at); n++; + } + + Widget menuItem = XmCreateToggleButtonGadget(menu, name, args, n); + XtManageChild(menuItem); + XmStringFree(s1); + if(at) XmStringFree(at); + + if(callback) { + XtAddCallback(menuItem, XmNvalueChangedCallback, (XtCallbackProc)callback, cbData); + } + + return menuItem; +} + static void WindowCreateMenu(MainWindow *win, Widget parent, Arg *mbargs, int nmbargs) { Widget menubar = XmCreateMenuBar(parent, "menubar", mbargs, nmbargs); XtManageChild(menubar); @@ -333,7 +374,7 @@ static void WindowCreateMenu(MainWindow *win, Widget parent, Arg *mbargs, int nm // menus XmString s = XmStringCreateSimple("File"); - Widget fileMenuItem = XtVaCreateManagedWidget( + XtVaCreateManagedWidget( "menuitem", xmCascadeButtonWidgetClass, menubar, @@ -343,7 +384,7 @@ static void WindowCreateMenu(MainWindow *win, Widget parent, Arg *mbargs, int nm Widget fileMenu = XmVaCreateSimplePulldownMenu(menubar, "menu", 0, NULL, NULL); s = XmStringCreateSimple("Playback"); - Widget playMenuItem = XtVaCreateManagedWidget( + XtVaCreateManagedWidget( "menuitem", xmCascadeButtonWidgetClass, menubar, @@ -364,6 +405,10 @@ static void WindowCreateMenu(MainWindow *win, Widget parent, Arg *mbargs, int nm // file menu createMenuItem(fileMenu, "fileOpen", "Open...", 'O', "CtrlO", "Ctrl+O", FileOpenCB, NULL); + createMenuItem(fileMenu, "fileQuit", "Exit", 'E', "CtrlQ", "Ctrl+Q", FileQuitCB, NULL); + + // play menu + createToggleMenuItem(playMenu, "playRepeatTrack", "Repeat", 'R', False, NULL, NULL, PlayRepeatCB, win); // view menu createMenuItem(viewMenu, "viewFullscreen", "Fullscreen", 'F', "F", "F", ViewFullscreenCB, NULL); @@ -485,6 +530,16 @@ static void FileOpenCB(Widget w, void *udata, void *cdata) { XtManageChild(dialog); } +static void FileQuitCB(Widget w, void *udata, void *cdata) { + WindowClosePlayer(main_window); + ApplicationExit(); +} + +static void PlayRepeatCB(Widget w, void *udata, void *cdata) { + MainWindow *win = udata; + win->repeatTrack = XmToggleButtonGadgetGetState(w); +} + static void ViewFullscreenCB(Widget w, void *udata, void *cdata) { if(main_window->fullscreen) { WindowFullscreen(main_window, FALSE); diff --git a/application/window.h b/application/window.h index 7230515..ad44fcb 100644 --- a/application/window.h +++ b/application/window.h @@ -65,6 +65,8 @@ typedef struct MainWindow { int mouse_y; int mouse_x_orig; int mouse_y_orig; + + Boolean repeatTrack; } MainWindow; MainWindow* WindowCreate(Display *dp);