]> uap-core.de Git - uwplayer.git/commitdiff
fix some crashes caused by uninitialized widget references
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 23 Nov 2025 08:34:15 +0000 (09:34 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 23 Nov 2025 08:34:15 +0000 (09:34 +0100)
application/Makefile
application/application.c
application/application.h
application/player.c
application/window.c

index 31fba461e116978b5e6405de17c6095f340282be..818413a04167765596c3a9cec9a74ba9d039c9b2 100644 (file)
@@ -33,7 +33,6 @@ CFLAGS += -I../ui/ -I../ucx -I..
 
 SRC = main.c
 SRC += application.c
-SRC += Fsb.c
 SRC += window.c
 SRC += player.c
 SRC += settings.c
index f7dbc053610dd0861404880f8e36b6436530d64d..beb620c900673da8bed5349567dd24d447f95ace 100644 (file)
@@ -67,7 +67,7 @@ void AppStart(UiEvent *event, AppStartupSettings *settings) {
     
     Display *display = ui_motif_get_display();
     MainWindow *window = WindowCreate(display);
-    toplevel_window = window->window;
+    toplevel_window = window->obj->window;
     if(settings->disable_adjust_window_size) {
         window->adjustWindowSize = FALSE;
         XtVaSetValues(window->viewAdjustWindowSize, XmNset, FALSE, NULL);
@@ -115,9 +115,19 @@ void AppSetPlayerWindow(Window w) {
 }
 
 
+static void file_selected(UiEvent *event, void *userdata) {
+    MainWindow *window = event->window;
+    UiFileList *flist = event->eventdata;
+    if(flist && flist->nfiles > 0) {
+        for(int i=0;i<flist->nfiles;i++) {
+            PlayListAddFile(window, flist->files[i]);
+        }
+        PlayListPlayNext(window, true);
+    }
+}
 
 void ActionOpen(UiEvent *event, void *userdata) {
-    
+    ui_openfiledialog(event->obj, 0, file_selected, NULL);
 }
 
 void ActionExit(UiEvent *event, void *userdata) {
index f53649abf22343e0f81dde00f32087d82f6c372f..74544a9d4cc1bc97e3dea4989f77c781e8d081e1 100644 (file)
@@ -75,7 +75,6 @@ typedef struct {
 typedef struct MainWindow {
     UiObject *obj;
     
-    Widget window;
     Widget menubar;
     Widget player_widget;
     Widget sidebar_scrolledwindow;
index 6da9fcd2dfbb6d06becbd2b5ead7df13137cbbb2..b452fdfde1d4d19b30c70af62acbb934d21b0a7a 100644 (file)
@@ -379,7 +379,7 @@ static Boolean player_widget_set_size(XtPointer data) {
     }
         
     Dimension win_width, win_height;
-    XtVaGetValues(win->window, XmNwidth, &win_width, XmNheight, &win_height, NULL);
+    XtVaGetValues(win->obj->widget, XmNwidth, &win_width, XmNheight, &win_height, NULL);
     Dimension player_width, player_height;
     XtVaGetValues(win->player_widget, XmNwidth, &player_width, XmNheight, &player_height, NULL);
 
@@ -387,7 +387,7 @@ static Boolean player_widget_set_size(XtPointer data) {
     Dimension new_height = player->height + win_height - player_height;
     
     // set window size
-    XtVaSetValues(win->window, XmNwidth, new_width, XmNheight, new_height, NULL);
+    XtVaSetValues(win->obj->widget, XmNwidth, new_width, XmNheight, new_height, NULL);
     
     // set window aspect ratio
     XSizeHints hints;
@@ -396,7 +396,7 @@ static Boolean player_widget_set_size(XtPointer data) {
     hints.min_aspect.y = new_height;
     hints.max_aspect.x = new_width;
     hints.max_aspect.y = new_height;
-    XSetWMNormalHints(XtDisplay(win->window), XtWindow(win->window), &hints);
+    XSetWMNormalHints(XtDisplay(win->obj->widget), XtWindow(win->obj->widget), &hints);
     
     return 0;
 }
index 47cd4b6e726937df60a8fb6e11bb75efcb41307a..f2d8539897e5da998c987d92465ca6c484716b47 100644 (file)
 #include "xdnd.h"
 #include "settings.h"
 
-#include "Fsb.h"
 #include "Sidebar.h"
 
 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 ViewFullscreenCB(Widget w, void *udata, void *cdata);
 static void ViewSidebarCB(Widget w, void *udata, void *cdata);
 static void ViewAdjustWindowSizeCB(Widget w, void *udata, void *cdata);
@@ -65,9 +62,6 @@ static void init_blank_cursor(Widget w) {
     blank_cursor_init = 1;
 }
 
-static void window_close_handler(Widget window, void *udata, void *cdata) {
-    FileQuitCB(window, NULL, NULL);
-}
 
 static unsigned int keycodeF;
 
@@ -106,7 +100,7 @@ static void WindowRealized(MainWindow *win) {
         init_blank_cursor(win->player_widget);
     }
     
-    XdndEnable(win->window);
+    XdndEnable(win->obj->widget);
 }
 
 static void playerWidgetInputCB(Widget widget, XtPointer u, XtPointer c) {
@@ -209,7 +203,7 @@ void WindowHandlePlayerEvent(MainWindow *win, XEvent *event) {
         
         
         if(win->pwbuttonpressed) {
-            Display *dp = XtDisplay(win->window);
+            Display *dp = XtDisplay(win->obj->widget);
                 
             XtUngrabPointer(win->player_widget, CurrentTime);
 
@@ -217,7 +211,7 @@ void WindowHandlePlayerEvent(MainWindow *win, XEvent *event) {
             memset(&xev, 0, sizeof(xev));
             xev.type = ClientMessage;
             xev.xclient.message_type = XInternAtom(dp, "_NET_WM_MOVERESIZE", False);
-            xev.xclient.window = XtWindow(win->window);
+            xev.xclient.window = XtWindow(win->obj->widget);
             xev.xclient.format = 32;
             xev.xclient.data.l[0] = x;
             xev.xclient.data.l[1] = y;
@@ -258,6 +252,8 @@ static UIWIDGET create_motif_listview(UiObject *obj, UiWidgetArgs *args, void *u
     Widget w = CreateSidebar(parent, "sidebar", a, n);
     SidebarSetWindow(w, window);
     
+    window->sidebar = w;
+    
     return w;
 }
 
@@ -527,7 +523,7 @@ static Atom net_wm_state_fullscreen;
 static int net_wm_atoms_initialized = 0;
 
 void WindowFullscreen(MainWindow *win, bool enableFullscreen) {
-    Display *dpy = XtDisplay(win->window);
+    Display *dpy = XtDisplay(win->obj->widget);
     
     // init net_wm_state atoms
     if(!net_wm_atoms_initialized) {
@@ -550,7 +546,7 @@ void WindowFullscreen(MainWindow *win, bool enableFullscreen) {
     XEvent ev;
     memset(&ev, 0, sizeof(XEvent));
     ev.type = ClientMessage;
-    ev.xclient.window = XtWindow(win->window);
+    ev.xclient.window = XtWindow(win->obj->widget);
     ev.xclient.message_type = net_wm_state;
     ev.xclient.format = 32;
     ev.xclient.data.l[0] = enableFullscreen ? 1 : 0;
@@ -569,58 +565,6 @@ void WindowMenubarSetVisible(MainWindow *win, bool visible) {
     }
 }
 
-static void filedialog_end(
-        Widget widget,
-        MainWindow *data,
-        XmFileSelectionBoxCallbackStruct *selection)
-{
-    XtUnmanageChild(widget);
-    XtDestroyWidget(widget);
-}
-
-static void filedialog_select(
-        Widget widget,
-        MainWindow *data,
-        XmFileSelectionBoxCallbackStruct *selection)
-{
-    char *value = NULL;
-    if(selection->value) {
-        XmStringGetLtoR(selection->value, XmSTRING_DEFAULT_CHARSET, &value);
-        if(value) {
-            PlayListAddFile(data, value);
-            PlayListPlayNext(data, true);
-            XtFree(value);
-        }
-    }
-    filedialog_end(widget, data, NULL);
-}
-
-
-
-
-static void FileOpenCB(Widget w, void *udata, void *cdata) {
-    MainWindow *win = main_window;
-    
-    Arg args[16];
-    int n = 0;
-    
-    XtSetArg(args[n], XnNshowViewMenu, 1); n++;
-    Widget dialog = XnCreateFileSelectionDialog(win->window, "dialog", args, n);
-    XtAddCallback(dialog, XmNokCallback, (XtCallbackProc)filedialog_select, win);
-    XtAddCallback(dialog, XmNcancelCallback, (XtCallbackProc)filedialog_end, win);
-    
-    Widget dirUp = XnFileSelectionBoxGetChild(dialog, XnFSB_DIR_UP_BUTTON);
-    XtUnmanageChild(dirUp);
-    
-    XtManageChild(dialog);
-}
-
-static void FileQuitCB(Widget w, void *udata, void *cdata) {
-    WindowClosePlayer(main_window);
-    ShutdownInstanceSocket(XtDisplay(w));
-    ApplicationExit();
-}
-
 static void ViewFullscreenCB(Widget w, void *udata, void *cdata) {
     if(main_window->fullscreen) {
         WindowFullscreen(main_window, FALSE);
@@ -672,7 +616,7 @@ void WindowAdjustAspectRatio(MainWindow *win) {
     // the video, because of window decoration, menubar and other extra controls)
     
     Dimension win_width, win_height;
-    XtVaGetValues(win->window, XmNwidth, &win_width, XmNheight, &win_height, NULL);
+    XtVaGetValues(win->obj->widget, XmNwidth, &win_width, XmNheight, &win_height, NULL);
     Dimension player_width, player_height;
     XtVaGetValues(win->player_widget, XmNwidth, &player_width, XmNheight, &player_height, NULL);
     
@@ -694,7 +638,7 @@ void WindowAdjustAspectRatio(MainWindow *win) {
     hints.max_aspect.x = new_width;
     hints.max_aspect.y = new_height;
     //printf("new size: %d x %d    current: %d x %d\n", (int)new_width, (int)new_height, (int)win_width, (int)win_height);
-    XSetWMNormalHints(XtDisplay(win->window), XtWindow(win->window), &hints);
+    XSetWMNormalHints(XtDisplay(win->obj->widget), XtWindow(win->obj->widget), &hints);
 }
 
 void WindowClosePlayer(MainWindow *win) {
@@ -727,5 +671,7 @@ void WindowShowSidebar(MainWindow *win, bool visible) {
 }
 
 void WindowUpdate(MainWindow *win) {
-    SidebarRepaint(win->sidebar);
+    if(win->sidebar) {
+        SidebarRepaint(win->sidebar);
+    }
 }