From: Olaf Wintermann Date: Sun, 23 Nov 2025 10:21:46 +0000 (+0100) Subject: hide the menubar in fullscreen mode X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=c9feb85d6f48fcebff0a9d85e1ba314ef087610d;p=uwplayer.git hide the menubar in fullscreen mode --- diff --git a/application/application.h b/application/application.h index 74544a9..82c086e 100644 --- a/application/application.h +++ b/application/application.h @@ -75,7 +75,6 @@ typedef struct { typedef struct MainWindow { UiObject *obj; - Widget menubar; Widget player_widget; Widget sidebar_scrolledwindow; Widget sidebar; diff --git a/application/window.c b/application/window.c index f2d8539..735cbad 100644 --- a/application/window.c +++ b/application/window.c @@ -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); diff --git a/ui/common/object.c b/ui/common/object.c index b041bc9..35da15f 100644 --- a/ui/common/object.c +++ b/ui/common/object.c @@ -32,6 +32,7 @@ #include "context.h" #include +#include #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); + } +} diff --git a/ui/common/object.h b/ui/common/object.h index e6dd3c3..4327875 100644 --- a/ui/common/object.h +++ b/ui/common/object.h @@ -30,10 +30,16 @@ #define UIC_OBJECT_H #include "../ui/toolkit.h" +#include #ifdef __cplusplus extern "C" { #endif + +typedef struct UiObjectPrivate { + UiObject obj; + CxMap *ext; +} UiObjectPrivate; typedef void (*ui_object_callback)(UiObject *obj, void *userdata); diff --git a/ui/common/utils.c b/ui/common/utils.c index c4823f3..5e01239 100644 --- a/ui/common/utils.c +++ b/ui/common/utils.c @@ -27,6 +27,7 @@ */ #include "utils.h" +#include "properties.h" #include @@ -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; + } + } +} diff --git a/ui/common/utils.h b/ui/common/utils.h index 688f24a..592ad4b 100644 --- a/ui/common/utils.h +++ b/ui/common/utils.h @@ -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 } diff --git a/ui/gtk/toolkit.c b/ui/gtk/toolkit.c index 87d1ef1..682d2e8 100644 --- a/ui/gtk/toolkit.c +++ b/ui/gtk/toolkit.c @@ -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 diff --git a/ui/gtk/window.c b/ui/gtk/window.c index f90997f..13c521e 100644 --- a/ui/gtk/window.c +++ b/ui/gtk/window.c @@ -35,6 +35,7 @@ #include "../common/context.h" #include "../common/menu.h" #include "../common/toolbar.h" +#include "../common/utils.h" #include @@ -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), diff --git a/ui/motif/menu.c b/ui/motif/menu.c index 345ef05..f3e1f41 100644 --- a/ui/motif/menu.c +++ b/ui/motif/menu.c @@ -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) { diff --git a/ui/motif/menu.h b/ui/motif/menu.h index efa99ce..4c40d79 100644 --- a/ui/motif/menu.h +++ b/ui/motif/menu.h @@ -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); diff --git a/ui/motif/window.c b/ui/motif/window.c index e447044..990b788 100644 --- a/ui/motif/window.c +++ b/ui/motif/window.c @@ -32,13 +32,15 @@ #include #include +#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; diff --git a/ui/motif/window.h b/ui/motif/window.h index 33bb66d..8c2c5ee 100644 --- a/ui/motif/window.h +++ b/ui/motif/window.h @@ -29,11 +29,18 @@ #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 diff --git a/ui/ui/toolkit.h b/ui/ui/toolkit.h index e65f0e5..7b8309a 100644 --- a/ui/ui/toolkit.h +++ b/ui/ui/toolkit.h @@ -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 diff --git a/ui/ui/window.h b/ui/ui/window.h index 83e85a3..27203c2 100644 --- a/ui/ui/window.h +++ b/ui/ui/window.h @@ -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);