]> uap-core.de Git - uwplayer.git/commitdiff
add menu callbacks
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 29 Oct 2025 20:53:06 +0000 (21:53 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 29 Oct 2025 20:53:06 +0000 (21:53 +0100)
application/application.c
application/application.h
application/window.c

index cc2a9eee44c84361f04bec087b7cc1e920332f95..6d0fef136a49a875cd3a28d3aa09861db3516d7b 100644 (file)
@@ -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);
+    }
+}
index 8b4b7ea8c0b74d7ba5477c15d31debd1d622b652..e8e1516dc31f286793a0f0a786996431f019c0bb 100644 (file)
@@ -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
index efbe2fbf024a5cca8139c5f515911390a97ef7d2..d2d2045a45f49291cf995cc9c63e9982f3278268 100644 (file)
@@ -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;