build
config.mk
+gmon.out
CFLAGS += -I../ui/ -I../ucx -I..
SRC = main.c
+SRC += application.c
SRC += Fsb.c
SRC += window.c
SRC += player.c
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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 */
+
#include <inttypes.h>
#include <sys/stat.h>
+#include "application.h"
#include "window.h"
#include "main.h"
#include "playlist.h"
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;
}
}
-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
//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) {
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;
}
}
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;
}
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);
- }
- }
-}
CxList* GetOpenFileArgs(void);
void CleanOpenFileArgs(void);
-void SetPlayerWindow(Window w);
-
-void AppMainLoop(XtAppContext app);
#ifdef __cplusplus
printf("wait_for_process player: %p\n", player);
player->isactive = FALSE;
player->status = status;
- SetPlayerWindow(0);
+ AppSetPlayerWindow(0);
PlayerUnref(player);
return NULL;
p->window = child[0];
XFree(child);
- SetPlayerWindow(p->window);
+ AppSetPlayerWindow(p->window);
XSelectInput(XtDisplay(win->player_widget), p->window, PointerMotionMask);
}
free(p->tmp);
}
- SetPlayerWindow(0);
+ AppSetPlayerWindow(0);
free(p);
}
#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;
} PlayList;
typedef struct MainWindow {
+ UiObject *obj;
+
Widget window;
Widget menubar;
Widget player_widget;