]> uap-core.de Git - uwplayer.git/commitdiff
hide the menubar in fullscreen mode
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 23 Nov 2025 10:21:46 +0000 (11:21 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 23 Nov 2025 10:21:46 +0000 (11:21 +0100)
14 files changed:
application/application.h
application/window.c
ui/common/object.c
ui/common/object.h
ui/common/utils.c
ui/common/utils.h
ui/gtk/toolkit.c
ui/gtk/window.c
ui/motif/menu.c
ui/motif/menu.h
ui/motif/window.c
ui/motif/window.h
ui/ui/toolkit.h
ui/ui/window.h

index 74544a9d4cc1bc97e3dea4989f77c781e8d081e1..82c086e2283eb8101c1e451430c2cd8e104a4e94 100644 (file)
@@ -75,7 +75,6 @@ typedef struct {
 typedef struct MainWindow {
     UiObject *obj;
     
-    Widget menubar;
     Widget player_widget;
     Widget sidebar_scrolledwindow;
     Widget sidebar;
index f2d8539897e5da998c987d92465ca6c484716b47..735cbadb9f819c687a356651647d769c320f8322 100644 (file)
@@ -532,14 +532,8 @@ void WindowFullscreen(MainWindow *win, bool enableFullscreen) {
         net_wm_atoms_initialized = 1;
     }
     
-    WindowMenubarSetVisible(win, !enableFullscreen);
-    if(enableFullscreen && !win->fullscreen) {
-        XtUnmanageChild(main_window->menubar);
-        main_window->fullscreen = TRUE;
-    } else if(!enableFullscreen && win->fullscreen) {
-        XtManageChild(main_window->menubar);
-        main_window->fullscreen = FALSE;
-    }
+    ui_window_menubar_set_visible(win->obj, !enableFullscreen);
+    win->fullscreen = enableFullscreen;
     
     WindowShowSidebar(win, enableFullscreen ? false : win->sidebarvisible);
     
@@ -555,16 +549,6 @@ void WindowFullscreen(MainWindow *win, bool enableFullscreen) {
     XSendEvent(dpy, DefaultRootWindow(dpy), False, SubstructureNotifyMask | SubstructureRedirectMask, &ev);
 }
 
-void WindowMenubarSetVisible(MainWindow *win, bool visible) {
-    if(visible) {
-        XtManageChild(main_window->menubar);
-        XtVaSetValues(main_window->player_widget, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, main_window->menubar, NULL);
-    } else {
-        XtUnmanageChild(main_window->menubar);
-        XtVaSetValues(main_window->player_widget, XmNtopAttachment, XmATTACH_FORM, NULL);
-    }
-}
-
 static void ViewFullscreenCB(Widget w, void *udata, void *cdata) {
     if(main_window->fullscreen) {
         WindowFullscreen(main_window, FALSE);
index b041bc9b22b4bf25c07902cc2b753d07d51a97fe..35da15f4f97ac4e06a2fa4ace8ae8f7a21a07840 100644 (file)
@@ -32,6 +32,7 @@
 #include "context.h"
 
 #include <cx/linked_list.h>
+#include <cx/hash_map.h>
 
 #include "../ui/container.h"
 
@@ -108,7 +109,7 @@ void uic_object_destroy(UiObject *obj) {
 UiObject* uic_object_new_toplevel(void) {
     fflush(stdout);
     CxMempool *mp = cxMempoolCreateSimple(256);
-    UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject));
+    UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObjectPrivate));
     fflush(stdout);
     obj->ctx = uic_context(obj, mp);
     obj->ctx->parent = ui_global_context();
@@ -119,7 +120,7 @@ UiObject* uic_object_new_toplevel(void) {
 }
 
 UiObject* uic_ctx_object_new(UiContext *ctx, UIWIDGET widget) {
-    UiObject *newobj = cxCalloc(ctx->allocator, 1, sizeof(UiObject));
+    UiObject *newobj = cxCalloc(ctx->allocator, 1, sizeof(UiObjectPrivate));
     newobj->ctx = ctx;
     newobj->widget = widget;
     uic_object_created(newobj);
@@ -170,3 +171,24 @@ void uic_object_remove_second_last_container(UiObject *toplevel) {
         fprintf(stderr, "Error: uic_object_remove_second_last_container expected at least 2 containers\n");
     }
 }
+
+// public API
+
+void ui_object_set(UiObject *obj, const char *key, void *data) {
+    UiObjectPrivate *p = (UiObjectPrivate*)obj;
+    if(!p->ext) {
+        p->ext = cxHashMapCreate(obj->ctx->mp->allocator, CX_STORE_POINTERS, 4);
+    }
+    if(data) {
+        cxMapPut(p->ext, key, data);
+    } else {
+        cxMapRemove(p->ext, key);
+    }
+}
+
+void* ui_object_get(UiObject *obj, const char *key) {
+    UiObjectPrivate *p = (UiObjectPrivate*)obj;
+    if(p->ext) {
+        return cxMapGet(p->ext, key);
+    }
+}
index e6dd3c3e2ddf8c2aaf63316766455d534e2c400e..43278752ef904f4cef2741721d3b639f66ff6832 100644 (file)
 #define        UIC_OBJECT_H
 
 #include "../ui/toolkit.h"
+#include <cx/map.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
+    
+typedef struct UiObjectPrivate {
+    UiObject obj;
+    CxMap *ext;
+} UiObjectPrivate;
 
 typedef void (*ui_object_callback)(UiObject *obj, void *userdata);
 
index c4823f3760480a6d5ab349edc90c059b1126cda9..5e01239b0290e15b5f9e18c1bdfdb9c9fbd978d7 100644 (file)
@@ -27,6 +27,7 @@
  */
 
 #include "utils.h"
+#include "properties.h"
 
 #include <cx/string.h>
 
@@ -69,3 +70,16 @@ UiPathElm* ui_default_pathelm_func(const char* full_path, size_t len, size_t* re
 
     return elms;
 }
+
+void ui_get_window_default_width(int *width, int *height) {
+    const char *width_str = ui_get_property("ui.window.width");
+    const char *height_str = ui_get_property("ui.window.height");
+    if(width_str && height_str) {
+        int w = atoi(width_str);
+        int h = atoi(height_str);
+        if(w > 0 && h > 0) {
+            *width = w;
+            *height = h;
+        }
+    }
+}
index 688f24a2a4f9917dad7e0d4d84da45798298b60a..592ad4b107d464284170007d02d50e578d6ef04c 100644 (file)
@@ -37,6 +37,12 @@ extern "C" {
 
 UiPathElm* ui_default_pathelm_func(const char* full_path, size_t len, size_t* ret_nelm, void* data);
 
+/*
+ * overrides width/height with values from
+ * ui.window.width and ui.window.height properties if available
+ */
+void ui_get_window_default_width(int *width, int *height);
+
 
 #ifdef __cplusplus
 }
index 87d1ef1240d3b61b9556356fd268ef4c05ad7e77..682d2e8ef8e273b67ee649df16223a8e3d87feec 100644 (file)
@@ -263,7 +263,7 @@ void ui_set_show_all(UIWIDGET widget, int value) {
 #endif
 }
 
-void ui_set_visible(UIWIDGET widget, int visible) {
+void ui_set_visible(UIWIDGET widget, UiBool visible) {
 #if GTK_MAJOR_VERSION >= 4
     gtk_widget_set_visible(widget, visible);
 #else
index f90997f32e39ba9f380bf021389de9ee05fe7820..13c521e730efa8afc729a527fe8a891739f08535 100644 (file)
@@ -35,6 +35,7 @@
 #include "../common/context.h"
 #include "../common/menu.h"
 #include "../common/toolbar.h"
+#include "../common/utils.h"
 
 #include <cx/mempool.h>
 
@@ -169,16 +170,7 @@ static UiObject* create_window(const char *title, void *window_data, UiBool side
     int window_width = window_default_width;
     int window_height = window_default_height;
     if(!simple) {
-        const char *width = ui_get_property("ui.window.width");
-        const char *height = ui_get_property("ui.window.height");
-        if(width && height) {
-            int w = atoi(width);
-            int h = atoi(height);
-            if(w > 0 && h > 0) {
-                window_width = w;
-                window_height = h;
-            }
-        }
+        ui_get_window_default_width(&window_width, &window_height);
     }
     gtk_window_set_default_size(
                 GTK_WINDOW(obj->widget),
index 345ef054a2a305da0cdf68a34cd6b17fb91dc119..f3e1f41d6f06cbb4546bd7e5b8889682591aec32 100644 (file)
@@ -55,10 +55,10 @@ static ui_menu_add_f createMenuItem[] = {
     /* UI_MENU_SEPARATOR       */ add_menuseparator_widget
 };
 
-void ui_create_menubar(UiObject *obj, Widget window) {
+Widget ui_create_menubar(UiObject *obj, Widget window) {
     UiMenu *menus_begin = uic_get_menu_list();
     if(!menus_begin) {
-        return;
+        return NULL;
     }
     
     Widget menubar = XmCreateMenuBar(window, "menubar", NULL, 0);
@@ -70,6 +70,8 @@ void ui_create_menubar(UiObject *obj, Widget window) {
         add_menu_widget(menubar, 0, &menu->item, obj);
         ls = (UiMenu*)ls->item.next;
     }
+    
+    return menubar;
 }
 
 void ui_add_menu_items(Widget parent, int i, UiMenu *menu, UiObject *obj) {
index efa99cefc5d20cf88b8832f6be3d16ac9b7c792b..4c40d797ff596e88f0dcdb6287a20b5deefcf9fb 100644 (file)
@@ -52,7 +52,7 @@ struct UiActiveMenuItemList {
     
 typedef void(*ui_menu_add_f)(Widget, int, UiMenuItemI*, UiObject*);
     
-void ui_create_menubar(UiObject *obj, Widget window);
+Widget ui_create_menubar(UiObject *obj, Widget window);
 void ui_add_menu_widget(Widget parent, int i, UiMenuItemI *item, UiObject *obj);
 
 void add_menu_widget(Widget parent, int i, UiMenuItemI *item, UiObject *obj);
index e447044ee81d1db1a72171407dd0fd9d19f982b3..990b7884c4b3bb21594c7376f40011ee8cc5fb75 100644 (file)
 #include <limits.h>
 #include <unistd.h>
 
+#include "window.h"
+
 #include "toolkit.h"
 #include "menu.h"
 #include "toolbar.h"
 #include "container.h"
 #include "pathbar.h"
-#include "../ui/window.h"
 #include "../common/context.h"
+#include "../common/utils.h"
 
 #include "Grid.h"
 #include "Fsb.h"
@@ -79,13 +81,22 @@ static UiObject* create_window(const char *title, void *window_data, Boolean sim
     obj->window = window_data;
     obj->destroy = ui_window_widget_destroy;
     
+    int window_width = window_default_width;
+    int window_height = window_default_height;
+    if(!simple) {
+        ui_get_window_default_width(&window_width, &window_height);
+    }
+    
+    UiMotifAppWindow *appwindow = cxZalloc(a, sizeof(UiMotifAppWindow));
+    ui_object_set(obj, "ui_motif_app_window", appwindow);
+    
     Arg args[16];
     int n = 0;
     XtSetArg(args[n], XmNtitle, title); n++;
     XtSetArg(args[n], XmNminWidth, 100); n++;
     XtSetArg(args[n], XmNminHeight, 50); n++;
-    XtSetArg(args[n], XmNwidth, window_default_width); n++;
-    XtSetArg(args[n], XmNheight, window_default_height); n++;
+    XtSetArg(args[n], XmNwidth, window_width); n++;
+    XtSetArg(args[n], XmNheight, window_height); n++;
     
     Widget toplevel = XtAppCreateShell(
             ui_appname(),
@@ -115,7 +126,7 @@ static UiObject* create_window(const char *title, void *window_data, Boolean sim
     
     // menu
     if(!simple) {
-        ui_create_menubar(obj, window);
+        appwindow->menubar = ui_create_menubar(obj, window);
     }
     
     // content frame
@@ -148,6 +159,26 @@ UiObject* ui_simple_window(const char *title, void *window_data) {
     return create_window(title, window_data, TRUE);
 }
 
+void ui_window_size(UiObject *obj, int width, int height) {
+    XtVaSetValues(obj->widget, XmNwidth, width, XmNheight, height, NULL);
+}
+
+void ui_window_default_size(int width, int height) {
+    window_default_width = width;
+    window_default_height = height;
+}
+
+void ui_window_menubar_set_visible(UiObject *obj, UiBool visible) {
+    UiMotifAppWindow *window = ui_object_get(obj, "ui_motif_app_window");
+    if(window) {
+        if(window->menubar) {
+            ui_set_visible(window->menubar, visible);
+        }
+    } else {
+        fprintf(stderr, "Error: obj is not an application window\n");
+    }
+}
+
 static void filedialog_event(UiEventData *event, int result, UiFileList flist) {
     UiEvent evt;
     evt.obj = event->obj;
index 33bb66d2e183c13032c6b46c2053086a5ca62b4a..8c2c5eeb49eb35d16ec0e48e28a270f003ee52db 100644 (file)
 #ifndef WINDOW_H
 #define WINDOW_H
 
+#include "../ui/window.h"
+#include "../ui/widget.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
+    
+#define UI_MOTIF_APP_WINDOW 0xabcd
 
-
+typedef struct UiMotifAppWindow {
+    Widget menubar;
+} UiMotifAppWindow;
 
 
 #ifdef __cplusplus
index e65f0e59dc345ca967d9bf7ba9b00278cfc46508..7b8309a3c0e3739752d489efff8589de3b84328b 100644 (file)
@@ -695,6 +695,9 @@ UIEXPORT void ui_list_class_set_count(UiList *list, int(*count)(UiList *list));
 UIEXPORT void ui_list_class_set_data(UiList *list, void *data);
 UIEXPORT void ui_list_class_set_iter(UiList *list, void *iter);
 
+UIEXPORT void ui_object_set(UiObject *obj, const char *key, void *data);
+UIEXPORT void* ui_object_get(UiObject *obj, const char *key);
+
 #ifdef __cplusplus
 }
 #endif
index 83e85a34dd3f65ec8b2d303f222134d7a4cd3b8b..27203c2d0333367d60235519424a616b7f3a2c2b 100644 (file)
@@ -83,6 +83,7 @@ UIEXPORT UiObject *ui_dialog_window_create(UiObject *parent, UiDialogWindowArgs
 
 UIEXPORT void ui_window_size(UiObject *obj, int width, int height);
 UIEXPORT void ui_window_default_size(int width, int height);
+UIEXPORT void ui_window_menubar_set_visible(UiObject *obj, UiBool visible);
 
 UIEXPORT void ui_splitview_window_set_pos(UiObject *obj, int pos);
 UIEXPORT int ui_splitview_window_get_pos(UiObject *obj);