From d082fd58d342036ef4217dfa86912fc956b76859 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Wed, 29 Oct 2025 21:53:06 +0100 Subject: [PATCH] add menu callbacks --- application/application.c | 137 ++++++++++++++++++++++++++++++++++++-- application/application.h | 12 ++++ application/window.c | 8 +++ 3 files changed, 153 insertions(+), 4 deletions(-) diff --git a/application/application.c b/application/application.c index cc2a9ee..6d0fef1 100644 --- a/application/application.c +++ b/application/application.c @@ -27,6 +27,7 @@ #include "window.h" #include "player.h" #include "playlist.h" +#include "settings.h" XtAppContext ui_motif_get_app(void); Display* ui_motif_get_display(void); @@ -42,10 +43,10 @@ void AppInitMenu(void) { ui_menuitem(.label = "Exit"); } ui_menu("Playback") { - ui_menu_toggleitem(.label = "Repeat", .varname = "repeat"); - ui_menu_toggleitem(.label = "Repeat List", .varname = "repeatlist"); - ui_menu_toggleitem(.label = "Random Playback", .varname = "random"); - ui_menu_toggleitem(.label = "Autoplay Folder", .varname = "autoplay"); + ui_menu_toggleitem(.label = "Repeat", .varname = "repeat", .onchange = ActionPlayRepeat); + ui_menu_toggleitem(.label = "Repeat List", .varname = "repeatlist", .onchange = ActionPlayRepeatList); + ui_menu_toggleitem(.label = "Random Playback", .varname = "random", .onchange = ActionPlayRandomCB); + ui_menu_toggleitem(.label = "Autoplay Folder", .varname = "autoplay", .onchange = ActionPlayRandomCB); ui_menuseparator(); ui_menuitem(.label = "Previous"); ui_menuitem(.label = "Next"); @@ -112,3 +113,131 @@ void AppMainLoop(XtAppContext app) { void AppSetPlayerWindow(Window w) { app_player_window = w; } + + + +void ActionPlayRepeat(UiEvent *event, void *userdata) { + if(event->set) { + return; + } + MainWindow *win = event->window; + win->playlist.playback = event->intval ? PLAYBACK_REPEAT : PLAYBACK_STOP; + ui_set(win->_playbackRepeatList, 0); + ui_set(win->_playbackAutoPlay, 0); + ui_set(win->_playbackRandom, 0); + + XtVaSetValues(win->playRepeatListButton, XmNset, 0, NULL); // TODO: remove + XtVaSetValues(win->playAutoPlayButton, XmNset, 0, NULL); // TODO: remove + XtVaSetValues(win->playRandom, XmNset, 0, NULL); // TODO: remove +} + +void ActionPlayRepeatList(UiEvent *event, void *userdata) { + if(event->set) { + return; + } + MainWindow *win = event->window; + win->playlist.playback = event->intval ? PLAYBACK_REPEAT_LIST : PLAYBACK_STOP; + ui_set(win->_playbackRepeat, 0); + ui_set(win->_playbackRandom, 0); + ui_set(win->_playbackAutoPlay, 0); + + XtVaSetValues(win->playRepeatTrackButton, XmNset, 0, NULL); // TODO: remove + XtVaSetValues(win->playAutoPlayButton, XmNset, 0, NULL); // TODO: remove + XtVaSetValues(win->playRandom, XmNset, 0, NULL); // TODO: remove +} + +void ActionPlayAutoPlayCB(UiEvent *event, void *userdata) { + if(event->set) { + return; + } + MainWindow *win = event->window; + win->playlist.playback = event->intval ? PLAYBACK_AUTOPLAY : PLAYBACK_STOP; + ui_set(win->_playbackRepeat, 0); + ui_set(win->_playbackRepeatList, 0); + ui_set(win->_playbackRandom, 0); + + XtVaSetValues(win->playRepeatTrackButton, XmNset, 0, NULL); // TODO: remove + XtVaSetValues(win->playRepeatListButton, XmNset, 0, NULL); // TODO: remove + XtVaSetValues(win->playRandom, XmNset, 0, NULL); // TODO: remove +} + +void ActionPlayRandomCB(UiEvent *event, void *userdata) { + if(event->set) { + return; + } + MainWindow *win = event->window; + win->playlist.playback = event->intval ? PLAYBACK_RANDOM : PLAYBACK_STOP; + ui_set(win->_playbackRepeat, 0); + ui_set(win->_playbackRepeatList, 0); + ui_set(win->_playbackAutoPlay, 0); + + XtVaSetValues(win->playRepeatTrackButton, XmNset, 0, NULL); // TODO: remove + XtVaSetValues(win->playRepeatListButton, XmNset, 0, NULL); // TODO: remove + XtVaSetValues(win->playAutoPlayButton, XmNset, 0, NULL); // TODO: remove +} + +void ActionPlayPreviousCB(UiEvent *event, void *userdata) { + MainWindow *win = event->window; + PlayListPlayPrev(win); +} + +void ActionPlayNextCB(UiEvent *event, void *userdata) { + MainWindow *win = event->window; + PlayListPlayNext(win, true); +} + +void ActionViewFullscreenCB(UiEvent *event, void *userdata) { + if(event->set) { + return; + } + MainWindow *win = event->window; + if(win->fullscreen) { + WindowFullscreen(win, FALSE); + } else { + WindowFullscreen(win, TRUE); + } +} + +void ActionViewSidebarCB(UiEvent *event, void *userdata) { + if(event->set) { + return; + } + MainWindow *win = event->window; + win->sidebarvisible = event->intval; + WindowShowSidebar(win, event->intval); +} + +void ActionViewAdjustWindowSizeCB(UiEvent *event, void *userdata) { + if(event->set) { + return; + } + MainWindow *win = event->window; + win->adjustWindowSize = event->intval; +} + +void ActionPrefSingleInstanceCB(UiEvent *event, void *userdata) { + if(event->set) { + return; + } + MainWindow *win = event->window; + + win->singleInstance = event->intval; + + Display *dp = ui_motif_get_display(); + + if(!win->singleInstance) { + ShutdownInstanceSocket(dp); + return; + } + + Bool disable_item = False; + if(CreateSingleInstanceSocket(dp, &disable_item)) { + // TODO: err + disable_item = True; + } + if(disable_item) { + win->singleInstance = 0; + //XmToggleButtonGadgetSetState(w, False, False); + ui_set(win->_singleInstance, 0); + } +} diff --git a/application/application.h b/application/application.h index 8b4b7ea..e8e1516 100644 --- a/application/application.h +++ b/application/application.h @@ -126,6 +126,18 @@ void AppStart(UiEvent *event, AppStartupSettings *settings); void AppMainLoop(XtAppContext app); +void ActionPlayRepeat(UiEvent *event, void *userdata); +void ActionPlayRepeatList(UiEvent *event, void *userdata); +void ActionPlayAutoPlayCB(UiEvent *event, void *userdata); +void ActionPlayRandomCB(UiEvent *event, void *userdata); +void ActionPlayPreviousCB(UiEvent *event, void *userdata); +void ActionPlayNextCB(UiEvent *event, void *userdata); +void ActionViewFullscreenCB(UiEvent *event, void *userdata); +void ActionViewSidebarCB(UiEvent *event, void *userdata); +void ActionViewAdjustWindowSizeCB(UiEvent *event, void *userdata); +void ActionPrefSingleInstanceCB(UiEvent *event, void *userdata); + + #ifdef __cplusplus } #endif diff --git a/application/window.c b/application/window.c index efbe2fb..d2d2045 100644 --- a/application/window.c +++ b/application/window.c @@ -268,8 +268,16 @@ MainWindow* WindowCreate(Display *display) { main_window = window; UiObject *obj = ui_window("uwplayer", NULL); + UiContext *ctx = obj->ctx; obj->window = window; window->obj = obj; + window->_sidebarVisible = ui_int_new(ctx, "sidebar"); + window->_playbackRepeat = ui_int_new(ctx, "repeat"); + window->_playbackRepeatList = ui_int_new(ctx, "repeatlist"); + window->_playbackRandom = ui_int_new(ctx, "random"); + window->_playbackAutoPlay = ui_int_new(ctx, "autoplay"); + window->_adjustWindowSize = ui_int_new(ctx, "adjustwindowsize"); + window->_singleInstance = ui_int_new(ctx, "singleinstance"); // toplevel window n = 0; -- 2.47.3