From c4d69d05f758eb2f8f98be04ff42456c9ae711fe Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Mon, 5 Sep 2022 13:54:33 +0200 Subject: [PATCH] add playlist scrollbar --- application/Sidebar.c | 43 ++++++++++++++++++++++++++++++++++++++----- application/main.c | 2 +- application/window.c | 16 +++++++++++----- application/window.h | 1 + 4 files changed, 51 insertions(+), 11 deletions(-) diff --git a/application/Sidebar.c b/application/Sidebar.c index 4faff71..3a2c29b 100644 --- a/application/Sidebar.c +++ b/application/Sidebar.c @@ -192,8 +192,18 @@ static void sidebar_destroy(Widget widget) { } +static int testresize = 1; static void sidebar_resize(Widget widget) { - + if(testresize) { + XtWidgetGeometry geom; + geom.request_mode = CWWidth | CWHeight; + geom.width = 200; + geom.height = 2000; + XtWidgetGeometry result; + //XtMakeGeometryRequest(widget, &geom, &result); + testresize = 0; + } + printf("resize\n"); } static int xdnd_initialized = 0; @@ -222,22 +232,44 @@ static void sidebar_realize(Widget widget, XtValueMask *mask, XSetWindowAttribut XtWindow(widget), visual, widget->core.colormap); + + Dimension w, h; + + Widget parent = XtParent(widget); + XtVaSetValues(parent, XmNbackground, WhitePixelOfScreen(XtScreen(parent)), NULL); + + XtMakeResizeRequest(widget, 200, 100, &w, &h); + + } static void sidebar_expose(Widget widget, XEvent *event, Region region) { //printf("expose\n"); Dimension w, h; - XtMakeResizeRequest(widget, 200, 200, &w, &h); + //XtMakeResizeRequest(widget, 200, 2000, &w, &h); - Sidebar s = (Sidebar)widget; - XftFont *xftFont = s->sidebar.font->fonts->font; + w = widget->core.width; + h = widget->core.height; + Widget parent = XtParent(widget); - XftDrawRect(s->sidebar.d, &s->sidebar.bg, 0, 0, s->core.width, s->core.height); + Sidebar s = (Sidebar)widget; + XftFont *xftFont = s->sidebar.font->fonts->font; + UcxList *tracks = s->sidebar.window->playlist.tracks; + size_t numTracks = ucx_list_size(tracks); int fontheight = xftFont->ascent; int height = s->sidebar.elmHeight; + int list_height = numTracks * height; + if((list_height > s->core.height) || (w < parent->core.width)) { + XtMakeResizeRequest(widget, parent->core.width, list_height, &w, &h); + } + + + XftDrawRect(s->sidebar.d, &s->sidebar.bg, 0, 0, w, h); + + //printf("current track: %d\n", s->sidebar.window->playlist.current_track); int i = 0; @@ -345,6 +377,7 @@ static void sidebar_xdnd_callback(Widget w, XtPointer udata, XtPointer cdata) { path[k] = '\0'; PlayListAddFile(s->sidebar.window, path); + SidebarRepaint((Widget)s); free(path); } diff --git a/application/main.c b/application/main.c index ecaf72b..e12d1aa 100644 --- a/application/main.c +++ b/application/main.c @@ -51,7 +51,7 @@ static String fallback[] = { "*pbbutton.shadowThickness: 1", "*pbbutton.highlightThickness: 1", - + "*XmText.baseTranslations: #override\\n" \ "Ctrl~Alt~Metav: paste-clipboard()\\n" \ "Ctrl~Alt~Metac: copy-clipboard()\\n" \ diff --git a/application/window.c b/application/window.c index 4cdeadc..7f1158c 100644 --- a/application/window.c +++ b/application/window.c @@ -307,10 +307,16 @@ MainWindow* WindowCreate(Display *display) { 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); + XtSetArg(args[n], XmNscrollingPolicy, XmAUTOMATIC); n++; + XtSetArg(args[n], XmNscrollBarDisplayPolicy, XmAS_NEEDED); n++; + XtSetArg(args[n], XmNspacing, 0); n++; + XtSetArg(args[n], XmNshadowThickness, 0); n++; + window->sidebar_scrolledwindow = XmCreateScrolledWindow(container, "sw_sidebar", args, n); + window->sidebar = CreateSidebar(window->sidebar_scrolledwindow, "sidebar", args, 0); SidebarSetWindow(window->sidebar, window); + XtManageChild(window->sidebar); //XtManageChild(window->sidebar); - + n = 0; XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; @@ -721,10 +727,10 @@ void WindowShowPlayerCursor(MainWindow *win) { void WindowShowSidebar(MainWindow *win, bool visible) { if(visible) { - XtManageChild(win->sidebar); - XtVaSetValues(win->player_widget, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, win->sidebar, NULL); + XtManageChild(win->sidebar_scrolledwindow); + XtVaSetValues(win->player_widget, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, win->sidebar_scrolledwindow, NULL); } else { - XtUnmanageChild(win->sidebar); + XtUnmanageChild(win->sidebar_scrolledwindow); XtVaSetValues(win->player_widget, XmNrightAttachment, XmATTACH_FORM, NULL); } } diff --git a/application/window.h b/application/window.h index dd44b88..77939b0 100644 --- a/application/window.h +++ b/application/window.h @@ -62,6 +62,7 @@ typedef struct MainWindow { Widget window; Widget menubar; Widget player_widget; + Widget sidebar_scrolledwindow; Widget sidebar; char *file; Player *player; -- 2.43.5