From: Olaf Wintermann Date: Fri, 7 Apr 2023 09:42:54 +0000 (+0200) Subject: fix dnd added empty file path to the playlist X-Git-Url: https://develop.uap-core.de/gitweb/uwplayer.git/commitdiff_plain/335105ec8330774af60183180c47b14e5aa4e6c1 fix dnd added empty file path to the playlist --- diff --git a/application/Sidebar.c b/application/Sidebar.c index 0b96328..733e21a 100644 --- a/application/Sidebar.c +++ b/application/Sidebar.c @@ -161,7 +161,7 @@ static void sidebar_init(Widget request, Widget neww, ArgList args, Cardinal *nu // initialize everything except XftDraw or other stuff that needs a Window - XftColor fg, bg; + XftColor fg, bg, sel2; fg.color.red = 0; fg.color.green = 0; fg.color.blue = 0; @@ -172,8 +172,16 @@ static void sidebar_init(Widget request, Widget neww, ArgList args, Cardinal *nu bg.color.blue = 0xFFFF; bg.color.alpha = 0xFFFF; + sel2.color.red = 0xFFFF; + sel2.color.green = 0xFFFF; + sel2.color.blue = 0; + sel2.color.alpha = 0xFFFF; + sb->sidebar.fg = fg; sb->sidebar.bg = bg; + sb->sidebar.select2_bg = sel2; + + sb->sidebar.select2 = -1; sb->sidebar.font = FontFromName(XtDisplay(neww), "Sans:size=11"); if(!sb->sidebar.font) { @@ -207,6 +215,13 @@ static void sidebar_resize(Widget widget) { printf("resize\n"); } + +static void remove_cb(Widget item, XtPointer index, XtPointer cd) { + printf("test_cb\n"); + fflush(stdout); +} + + static int xdnd_initialized = 0; static void sidebar_realize(Widget widget, XtValueMask *mask, XSetWindowAttributes *attributes) { @@ -240,7 +255,15 @@ static void sidebar_realize(Widget widget, XtValueMask *mask, XSetWindowAttribut XtVaSetValues(parent, XmNbackground, WhitePixelOfScreen(XtScreen(parent)), NULL); XtMakeResizeRequest(widget, 200, 100, &w, &h); - + + + XmString s1 = XmStringCreateSimple("Remove"); + sb->sidebar.popupMenu = XmVaCreateSimplePopupMenu( + widget, "popup", remove_cb, + //XmNuserData, widget, + XmVaPUSHBUTTON, s1, 'R', NULL, NULL, + NULL); + XmStringFree(s1); } static void sidebar_expose(Widget widget, XEvent *event, Region region) { @@ -280,6 +303,8 @@ static void sidebar_expose(Widget widget, XEvent *event, Region region) { if(i.index == s->sidebar.window->playlist.current_track) { XftDrawRect(s->sidebar.d, &s->sidebar.fg, 0, i.index*height, s->core.width, height); cg = &s->sidebar.bg; + } else if(i.index == s->sidebar.select2) { + XftDrawRect(s->sidebar.d, &s->sidebar.select2_bg, 0, i.index*height, s->core.width, height); } XftDrawString8(s->sidebar.d, cg, s->sidebar.font->fonts->font, 10, i.index*height + xftFont->ascent, (const FcChar8*)name, strlen(name)); @@ -312,16 +337,32 @@ static void SelectElmAP(Widget w, XEvent *event, String *args, Cardinal *nArgs) int selected = e->y / s->sidebar.elmHeight; PlayListPlayTrack(s->sidebar.window, selected); + s->sidebar.select2 = -1; SidebarRepaint(w); } static void PopupAP(Widget w, XEvent *event, String *args, Cardinal *nArgs) { + XButtonEvent *e = &event->xbutton; + Sidebar s = (Sidebar)w; + + int selected = e->y / s->sidebar.elmHeight; + s->sidebar.select2 = selected; + SidebarRepaint(w); + //printf("btn3\n"); + //fflush(stdout); + + XmMenuPosition(s->sidebar.popupMenu, &event->xbutton); + XtManageChild(s->sidebar.popupMenu); } static void open_uri(Sidebar s, cxstring uri) { + if(uri.length == 0) { + return; + } + const char *urilist = uri.ptr; size_t len = uri.length; diff --git a/application/SidebarP.h b/application/SidebarP.h index de4ceb7..055966a 100644 --- a/application/SidebarP.h +++ b/application/SidebarP.h @@ -57,6 +57,10 @@ typedef struct SidebarPart { NFont *font; XftColor fg; XftColor bg; + XftColor select2_bg; + + Widget popupMenu; + int select2; int elmHeight; diff --git a/application/playlist.c b/application/playlist.c index eb9dfc0..e32110d 100644 --- a/application/playlist.c +++ b/application/playlist.c @@ -28,6 +28,7 @@ #include "utils.h" #include +#include void PlayListInit(MainWindow *win) { win->playlist.tracks = cxArrayListCreate(cxDefaultAllocator, NULL, CX_STORE_POINTERS, 64); diff --git a/application/utils.c b/application/utils.c index a383a2e..5d18fdb 100644 --- a/application/utils.c +++ b/application/utils.c @@ -65,6 +65,9 @@ char* util_concat_path(const char *url_base, const char *p) { const char* util_resource_name(const char *url) { cxstring urlstr = cx_str(url); + if(urlstr.length == 0) { + return url; + } if(urlstr.ptr[urlstr.length-1] == '/') { urlstr.length--; }