]> uap-core.de Git - uwplayer.git/commitdiff
move some initialization code to application.c
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 29 Oct 2025 19:33:43 +0000 (20:33 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 29 Oct 2025 19:33:43 +0000 (20:33 +0100)
.gitignore
application/Makefile
application/application.c [new file with mode: 0644]
application/application.h [new file with mode: 0644]
application/main.c
application/main.h
application/player.c
application/window.h

index 5a5d5289651c4db9f4eaeefff6ca714fd387cb0e..478ee0c9ca018195be660cf86e128ce51107cf3d 100644 (file)
@@ -1,2 +1,3 @@
 build
 config.mk
+gmon.out
index 011717cb6dc892863423722db52e725da408597d..6569066f2f258f57363b75bf3ea135b06cab41cd 100644 (file)
@@ -32,6 +32,7 @@ include $(BUILD_ROOT)/config.mk
 CFLAGS += -I../ui/ -I../ucx -I..
 
 SRC = main.c
+SRC += application.c
 SRC += Fsb.c
 SRC += window.c
 SRC += player.c
diff --git a/application/application.c b/application/application.c
new file mode 100644 (file)
index 0000000..34b9ceb
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2025 Olaf Wintermann
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a 
+ * copy of this software and associated documentation files (the "Software"), 
+ * to deal in the Software without restriction, including without limitation 
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
+ * and/or sell copies of the Software, and to permit persons to whom the 
+ * Software is furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in 
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+
+#include <time.h>
+
+#include "application.h"
+#include "window.h"
+#include "player.h"
+#include "playlist.h"
+
+XtAppContext ui_motif_get_app(void);
+Display* ui_motif_get_display(void);
+
+static Widget toplevel_window;
+
+static Window app_player_window = 0;
+
+
+void AppInitMenu(void) {
+    // TODO
+}
+
+void AppStart(UiEvent *event, AppStartupSettings *settings) {
+    AppInitMenu();
+    
+    Display *display = ui_motif_get_display();
+    MainWindow *window = WindowCreate(display);
+    toplevel_window = window->window;
+    if(settings->disable_adjust_window_size) {
+        window->adjustWindowSize = FALSE;
+        XtVaSetValues(window->viewAdjustWindowSize, XmNset, FALSE, NULL);
+    }
+    
+    // random numbers used for creating tmp dirs and for random playback
+    srand(time(NULL));
+    
+    if(settings->playback != 0) {
+        PlayListSetMode(window, settings->playback);
+    }
+    
+    if(settings->single_instance) {
+        // this will trigger the Single Instance menu button event handler
+        // and enable the single instance mode if possible
+        XmToggleButtonGadgetSetState(window->prefSingleInstanceButton, True, True);
+    }
+      
+    WindowShow(window);
+    
+#ifdef UI_MOTIF
+    XtAppContext app = ui_motif_get_app();
+    AppMainLoop(app);
+#endif
+}
+
+/*
+ * Extended Xt main loop, that also handles external window events
+ */
+void AppMainLoop(XtAppContext app) {
+    while(!XtAppGetExitFlag(app)) {
+        XEvent event;
+        XtAppNextEvent(app, &event);
+        
+        if(app_player_window != 0 && event.xany.window == app_player_window) {
+            WindowHandlePlayerEvent(GetMainWindow(), &event);
+        } else {
+            XtDispatchEvent(&event);
+        }
+    }
+}
+
+void AppSetPlayerWindow(Window w) {
+    app_player_window = w;
+}
diff --git a/application/application.h b/application/application.h
new file mode 100644 (file)
index 0000000..6f17ee1
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2025 Olaf Wintermann
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a 
+ * copy of this software and associated documentation files (the "Software"), 
+ * to deal in the Software without restriction, including without limitation 
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
+ * and/or sell copies of the Software, and to permit persons to whom the 
+ * Software is furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in 
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef UWP_APPLICATION_H
+#define UWP_APPLICATION_H
+
+#include <ui/ui.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+    
+typedef enum PlaybackMode {
+    PLAYBACK_STOP = 0,
+    PLAYBACK_REPEAT,
+    PLAYBACK_REPEAT_LIST,
+    PLAYBACK_RANDOM,
+    PLAYBACK_AUTOPLAY
+} PlaybackMode;
+    
+typedef struct AppStartupSettings {
+    PlaybackMode playback;
+    bool fullscreen;
+    bool disable_adjust_window_size;
+    bool single_instance;
+} AppStartupSettings;
+
+
+void AppSetPlayerWindow(Window w);
+
+void AppInitMenu(void);
+
+void AppStart(UiEvent *event, AppStartupSettings *settings);
+
+void AppMainLoop(XtAppContext app);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* UWP_APPLICATION_H */
+
index 163e557fa1b720aa464db40a843c28f4560393ba..3bc610156a54f47e77fa3ebb00481d654ad2f039 100644 (file)
@@ -29,6 +29,7 @@
 #include <inttypes.h>
 #include <sys/stat.h>
 
+#include "application.h"
 #include "window.h"
 #include "main.h"
 #include "playlist.h"
@@ -41,7 +42,9 @@
 
 static XtAppContext app;
 static Display *display;
-static Widget toplevel_window;
+
+XtAppContext ui_motif_get_app(void);
+Display* ui_motif_get_display(void);
 
 static CxList *open_file_arg;
 
@@ -89,8 +92,7 @@ static void input_proc(XtPointer data, int *source, XtInputId *iid) {
     }
 }
 
-XtAppContext ui_motif_get_app(void);
-Display* ui_motif_get_display(void);
+
 
 int main(int argc, char** argv) {  
     // disable stdout buffering, because the netbeans's internal terminal
@@ -115,10 +117,12 @@ int main(int argc, char** argv) {
     //display = XtOpenDisplay(app, NULL, APP_NAME, APP_CLASS, NULL, 0, &argc, argv);
     display = ui_motif_get_display();
     
-    PlaybackMode playback = PLAYBACK_STOP;
-    bool fullscreen = FALSE;
-    bool disable_adjust_window_size = FALSE;
-    bool single_instance = FALSE;
+    AppStartupSettings settings = {
+        .playback = PLAYBACK_STOP,
+        .fullscreen = FALSE,
+        .disable_adjust_window_size = FALSE,
+        .single_instance = FALSE
+    };
     
     bool file_args = 0;
     if(argc > 1) {
@@ -142,37 +146,37 @@ int main(int argc, char** argv) {
                         switch(arg[a]) {
                             case 't': {
                                 // repeat (Track)
-                                playback = PLAYBACK_REPEAT;
+                                settings.playback = PLAYBACK_REPEAT;
                                 break;
                             }
                             case 'l': {
                                 // repeat List
-                                playback = PLAYBACK_REPEAT_LIST;
+                                settings.playback = PLAYBACK_REPEAT_LIST;
                                 break;
                             }
                             case 'r': {
                                 // Random playback
-                                playback = PLAYBACK_RANDOM;
+                                settings.playback = PLAYBACK_RANDOM;
                                 break;
                             }
                             case 'a': {
                                 // Autoplay
-                                playback = PLAYBACK_AUTOPLAY;
+                                settings.playback = PLAYBACK_AUTOPLAY;
                                 break;
                             }
                             case 'w': {
                                 // disable adjust Window size
-                                disable_adjust_window_size = TRUE;
+                                settings.disable_adjust_window_size = TRUE;
                                 break;
                             }
                             case 'f': {
                                 // Fullscreen
-                                fullscreen = TRUE;
+                                settings.fullscreen = TRUE;
                                 break;
                             }
                             case 's': {
                                 // single instance
-                                single_instance = TRUE;
+                                settings.single_instance = TRUE;
                                 break;
                             }
                         }
@@ -212,34 +216,8 @@ int main(int argc, char** argv) {
             input_proc,
             NULL);
     
-    MainWindow *window = WindowCreate(display);
-    toplevel_window = window->window;
-    if(disable_adjust_window_size) {
-        window->adjustWindowSize = FALSE;
-        XtVaSetValues(window->viewAdjustWindowSize, XmNset, FALSE, NULL);
-    }
-    
-    // random numbers used for creating tmp dirs and for random playback
-    srand(time(NULL));
-    
-    if(playback != 0) {
-        PlayListSetMode(window, playback);
-    }
-    
-    if(single_instance) {
-        // this will trigger the Single Instance menu button event handler
-        // and enable the single instance mode if possible
-        XmToggleButtonGadgetSetState(window->prefSingleInstanceButton, True, True);
-    }
-      
-    WindowShow(window);
-    
-#ifndef UI_MOTIF
+    ui_onstartup((ui_callback)AppStart, &settings);
     ui_main();
-#else
-    AppMainLoop(app);
-#endif  
-    
     
     return 0;
 }
@@ -268,24 +246,3 @@ void CleanOpenFileArgs(void) {
     open_file_arg = NULL;
 }
 
-static Window app_player_window = 0;
-
-void SetPlayerWindow(Window w) {
-    app_player_window = w;
-}
-
-/*
- * Extended Xt main loop, that also handles external window events
- */
-void AppMainLoop(XtAppContext app) {
-    while(!XtAppGetExitFlag(app)) {
-        XEvent event;
-        XtAppNextEvent(app, &event);
-        
-        if(app_player_window != 0 && event.xany.window == app_player_window) {
-            WindowHandlePlayerEvent(GetMainWindow(), &event);
-        } else {
-            XtDispatchEvent(&event);
-        }
-    }
-}
index de79d8aa07637a5e21dca02dd74f38b468021b45..6d2b642a00615316262dd1364b085a01d0cd0f7c 100644 (file)
@@ -42,9 +42,6 @@ void AppExecProc(XtWorkProc proc, XtPointer data);
 CxList* GetOpenFileArgs(void);
 void CleanOpenFileArgs(void);
 
-void SetPlayerWindow(Window w);
-
-void AppMainLoop(XtAppContext app);
 
 
 #ifdef __cplusplus
index 6ff7377bfaaf2ad4e641e1df238ebf4447216f26..a6a1f46e9c716d7bedc9c5c380c661567878ded0 100644 (file)
@@ -117,7 +117,7 @@ static void* wait_for_process(void *data) {
     printf("wait_for_process player: %p\n", player);
     player->isactive = FALSE;
     player->status = status;
-    SetPlayerWindow(0);
+    AppSetPlayerWindow(0);
     PlayerUnref(player);
     
     return NULL;
@@ -445,7 +445,7 @@ static Boolean get_player_window(XtPointer data) {
         p->window = child[0];
         XFree(child);
         
-        SetPlayerWindow(p->window);
+        AppSetPlayerWindow(p->window);
         XSelectInput(XtDisplay(win->player_widget), p->window, PointerMotionMask);
     }
     
@@ -523,7 +523,7 @@ void PlayerUnref(Player *p) {
         free(p->tmp);
     }
     
-    SetPlayerWindow(0); 
+    AppSetPlayerWindow(0); 
     free(p);
 }
 
index 7df9825231a4ffed0ee01377e9107ba443240e0b..90207cb5e75766ed35071a3155892a46d7b66708 100644 (file)
@@ -24,6 +24,8 @@
 #ifndef UWP_WINDOW_H
 #define UWP_WINDOW_H
 
+#include <ui/ui.h>
+
 #include <Xm/XmAll.h>
 #include <stdbool.h>
 #include <inttypes.h>
 #include <cx/list.h>
 #include <cx/linked_list.h>
 
+#include "application.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
     
-typedef enum PlaybackMode {
-    PLAYBACK_STOP = 0,
-    PLAYBACK_REPEAT,
-    PLAYBACK_REPEAT_LIST,
-    PLAYBACK_RANDOM,
-    PLAYBACK_AUTOPLAY
-} PlaybackMode;
+
 
 typedef struct Player {
     char *tmp;
@@ -68,6 +66,8 @@ typedef struct {
 } PlayList;
 
 typedef struct MainWindow {
+    UiObject *obj;
+    
     Widget window;
     Widget menubar;
     Widget player_widget;