From: Olaf Wintermann Date: Sun, 20 Feb 2022 09:43:50 +0000 (+0100) Subject: add empty sidebar X-Git-Url: https://develop.uap-core.de/gitweb/uwplayer.git/commitdiff_plain/5f4caf1ec3793937210c83b45c54bc4264e30c58 add empty sidebar --- diff --git a/application/Makefile b/application/Makefile index 8b53092..97ddd55 100644 --- a/application/Makefile +++ b/application/Makefile @@ -38,6 +38,7 @@ SRC += player.c SRC += settings.c SRC += utils.c SRC += json.c +SRC += Sidebar.c OBJ = $(SRC:%.c=$(BUILD_ROOT)/build/application/%.$(OBJ_EXT)) diff --git a/application/Sidebar.c b/application/Sidebar.c new file mode 100644 index 0000000..b8c2f02 --- /dev/null +++ b/application/Sidebar.c @@ -0,0 +1,201 @@ +/* + * Copyright 2022 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 "Sidebar.h" +#include "SidebarP.h" + +#include +#include +#include + + +static void sidebar_class_init(void); +static void sidebar_class_part_init (WidgetClass wc); +static void sidebar_init(Widget request, Widget neww, ArgList args, Cardinal *num_args); +static void sidebar_destroy(Widget widget); +static void sidebar_resize(Widget widget); +static void sidebar_realize(Widget widget, XtValueMask *mask, XSetWindowAttributes *attributes); +static void sidebar_expose(Widget widget, XEvent *event, Region region); +static Boolean sidebar_set_values(Widget old, Widget request, Widget neww, ArgList args, Cardinal *num_args); +static void sidebar_insert_child(Widget child); +Boolean sidebar_acceptfocus(Widget widget, Time *time); +static void FocusInAP(Widget w, XEvent *event, String *args, Cardinal *nArgs); + + +static XtResource resources[] = { + +}; + +static XtActionsRec actionslist[] = { + {"focusIn", FocusInAP}, + {"NULL", NULL} +}; + +static char defaultTranslations[] = ": focusIn()"; + + +static XtResource constraints[] = {}; + +SidebarClassRec sidebarWidgetClassRec = { + // Core Class + { + (WidgetClass)&xmManagerClassRec, + "XnSidebar", // class_name + sizeof(SidebarRec), // widget_size + sidebar_class_init, // class_initialize + sidebar_class_part_init, // class_part_initialize + FALSE, // class_inited + sidebar_init, // initialize + NULL, // initialize_hook + sidebar_realize, // realize + actionslist, // actions + XtNumber(actionslist), // num_actions + resources, // resources + XtNumber(resources), // num_resources + NULLQUARK, // xrm_class + True, // compress_motion + True, // compress_exposure + True, // compress_enterleave + False, // visible_interest + sidebar_destroy, // destroy + sidebar_resize, // resize + sidebar_expose, // expose + sidebar_set_values, // set_values + NULL, // set_values_hook + XtInheritSetValuesAlmost, // set_values_almost + NULL, // get_values_hook + sidebar_acceptfocus, // accept_focus + XtVersion, // version + NULL, // callback_offsets + defaultTranslations, // tm_table + XtInheritQueryGeometry, // query_geometry + XtInheritDisplayAccelerator, // display_accelerator + NULL, // extension + }, + // Composite Class + { + XtInheritGeometryManager, // geometry_manager + XtInheritChangeManaged, // change_managed + sidebar_insert_child, // insert_child + XtInheritDeleteChild, // delete_child + NULL, // extension + }, + // Constraint Class + { + constraints, // resources + XtNumber(constraints), // num_resources + sizeof(XmFormConstraintRec), // constraint_size + NULL, // initialize + NULL, // destroy + NULL, // set_value + NULL, // extension + }, + // XmManager Class + { + XtInheritTranslations, // translations + NULL, // syn_resources + 0, // num_syn_resources + NULL, // syn_constraint_resources + 0, // num_syn_constraint_resources + XmInheritParentProcess, // parent_process + NULL // extension + }, + // Sidebar Class + { + 0 + } +}; + +WidgetClass xnSidebarWidgetClass = (WidgetClass)&sidebarWidgetClassRec; + + +static void sidebar_class_init(void) { + +} + +static void sidebar_class_part_init (WidgetClass wc) { + SidebarClassRec *sidebarClass = (SidebarClassRec*)wc; + XmManagerClassRec *managerClass = (XmManagerClassRec*)xmManagerWidgetClass; + + sidebarClass->constraint_class.initialize = managerClass->constraint_class.initialize; + sidebarClass->constraint_class.set_values = managerClass->constraint_class.set_values; +} + + + +static void sidebar_init(Widget request, Widget neww, ArgList args, Cardinal *num_args) { + +} + + + +static void sidebar_destroy(Widget widget) { + +} + +static void sidebar_resize(Widget widget) { + +} + +static void sidebar_realize(Widget widget, XtValueMask *mask, XSetWindowAttributes *attributes) { + (xmManagerClassRec.core_class.realize)(widget, mask, attributes); + + +} + +static void sidebar_expose(Widget widget, XEvent *event, Region region) { + printf("expose\n"); + Dimension w, h; + XtMakeResizeRequest(widget, 200, 200, &w, &h); +} + +static Boolean sidebar_set_values(Widget old, Widget request, Widget neww, ArgList args, Cardinal *num_args) { + Boolean r = False; + + return r; +} + +static void sidebar_insert_child(Widget child) { + (xmManagerClassRec.composite_class.insert_child)(child); +} + +Boolean sidebar_acceptfocus(Widget widget, Time *time) { + return 0; +} + + +static void FocusInAP(Widget w, XEvent *event, String *args, Cardinal *nArgs) { + +} + + + +/* --------------------------- public --------------------------- */ + +Widget CreateSidebar( + Widget parent, + String name, + ArgList arglist, + Cardinal argcount) +{ + return XtCreateWidget(name, xnSidebarWidgetClass, parent, arglist, argcount); +} diff --git a/application/Sidebar.h b/application/Sidebar.h new file mode 100644 index 0000000..351c647 --- /dev/null +++ b/application/Sidebar.h @@ -0,0 +1,45 @@ +/* + * Copyright 2022 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 SIDEBAR_H +#define SIDEBAR_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +Widget CreateSidebar( + Widget parent, + String name, + ArgList arglist, + Cardinal argcount); + + +#ifdef __cplusplus +} +#endif + +#endif /* SIDEBAR_H */ + diff --git a/application/SidebarP.h b/application/SidebarP.h new file mode 100644 index 0000000..057e0f0 --- /dev/null +++ b/application/SidebarP.h @@ -0,0 +1,78 @@ +/* + * Copyright 2022 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 SIDEBARP_H +#define SIDEBARP_H + + +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SidebarData SidebarData; +struct SidebarData { + int a; +}; + + +typedef struct SidebarClassPart { + int unused; +} SidebarClassPart; + +typedef struct SidebarClassRec { + CoreClassPart core_class; + CompositeClassPart composite_class; + ConstraintClassPart constraint_class; + XmManagerClassPart manager_class; + SidebarClassPart sidebar_class; +} SidebarClassRec; + +typedef struct SidebarPart { + int a; +} SidebarPart; + +typedef struct SidebarRec { + CorePart core; + CompositePart composite; + ConstraintPart constraint; + XmManagerPart manager; + SidebarPart sidebar; +} SidebarRec; + +typedef struct SidebarRec *Sidebar; + + +#ifdef __cplusplus +} +#endif + +#endif /* SIDEBARP_H */ + diff --git a/application/window.c b/application/window.c index c011084..b3f24d7 100644 --- a/application/window.c +++ b/application/window.c @@ -29,6 +29,7 @@ #include "player.h" #include "Fsb.h" +#include "Sidebar.h" static MainWindow *main_window; @@ -40,6 +41,7 @@ static void PlayRepeatCB(Widget w, void *udata, void *cdata); static void PlayRepeatListCB(Widget w, void *udata, void *cdata); static void PlayAutoPlayCB(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 WindowRealized(MainWindow *win); @@ -181,6 +183,10 @@ void WindowHandlePlayerEvent(MainWindow *win, XEvent *event) { if(etype == MotionNotify) { Time cur_motion_time = event->xmotion.time; + if(win->player) { + win->motion_playback_time = win->player->playback_time; + } + int x = event->xmotion.x_root; int y = event->xmotion.y_root; if(win->cursorhidden && cur_motion_time - win->player_event_time < IGNORE_MOTION_THRESHOLD_MS) { @@ -285,8 +291,18 @@ MainWindow* WindowCreate(Display *display) { WindowCreateMenu(window, container, args, n); n = 0; + XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; + XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; + XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++; + XtSetArg(args[n], XmNtopWidget, window->menubar); n++; + XtSetArg(args[n], XmNwidth, 300); n++; + window->sidebar = CreateSidebar(container, "sidebar", args, n); + //XtManageChild(window->sidebar); + + n = 0; XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; + XtSetArg(args[n], XmNrightWidget, window->sidebar); n++; XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++; XtSetArg(args[n], XmNtopWidget, window->menubar); n++; @@ -299,7 +315,7 @@ MainWindow* WindowCreate(Display *display) { EnterWindowMask | KeyPressMask | KeyReleaseMask | LeaveWindowMask, FALSE, playerEH, window); - + // get F keycode keycodeF = XKeysymToKeycode(XtDisplay(window->window), XStringToKeysym("F")); @@ -445,6 +461,7 @@ static void WindowCreateMenu(MainWindow *win, Widget parent, Arg *mbargs, int nm // view menu createMenuItem(viewMenu, "viewFullscreen", "Fullscreen", 'F', "F", "F", ViewFullscreenCB, NULL); + win->viewSidebarButton = createToggleMenuItem(viewMenu, "viewSidebar", "View Sidebar", 'S', False, NULL, NULL, ViewSidebarCB, win); } void go_fullscreen(Display *dsp, Window win) @@ -600,8 +617,17 @@ static void ViewFullscreenCB(Widget w, void *udata, void *cdata) { WindowFullscreen(main_window, FALSE); } else { WindowFullscreen(main_window, TRUE); + } +} + +static void ViewSidebarCB(Widget w, void *udata, void *cdata) { + MainWindow *win = udata; + XmToggleButtonCallbackStruct *cb = cdata; + if(cb->set) { + WindowShowSidebar(win); + } else { + WindowHideSidebar(win); } - } void WindowAdjustAspectRatio(MainWindow *win) { @@ -656,3 +682,14 @@ void WindowShowPlayerCursor(MainWindow *win) { } win->cursorhidden = False; } + +void WindowHideSidebar(MainWindow *win) { + XtUnmanageChild(win->sidebar); + XtVaSetValues(win->player_widget, XmNrightAttachment, XmATTACH_FORM, NULL); +} + +void WindowShowSidebar(MainWindow *win) { + XtManageChild(win->sidebar); + XtVaSetValues(win->player_widget, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, win->sidebar, NULL); +} + diff --git a/application/window.h b/application/window.h index 05385cc..e3202c0 100644 --- a/application/window.h +++ b/application/window.h @@ -51,10 +51,12 @@ typedef struct MainWindow { Widget window; Widget menubar; Widget player_widget; + Widget sidebar; char *file; Player *player; bool fullscreen; bool mbvisible; + bool sidebarvisible; bool cursorhidden; bool buttongrab; bool pwbuttonpressed; @@ -62,6 +64,7 @@ typedef struct MainWindow { Widget playRepeatTrackButton; Widget playRepeatListButton; Widget playAutoPlayButton; + Widget viewSidebarButton; Time player_event_time; Time button_press_time; @@ -95,6 +98,9 @@ void WindowShowPlayerCursor(MainWindow *win); void WindowHandlePlayerEvent(MainWindow *win, XEvent *event); +void WindowHideSidebar(MainWindow *win); +void WindowShowSidebar(MainWindow *win); + #ifdef __cplusplus } #endif