]> uap-core.de Git - uwplayer.git/commitdiff
handle btn1 in sidebar, switchable tracks
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 4 Sep 2022 08:09:42 +0000 (10:09 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 4 Sep 2022 08:09:42 +0000 (10:09 +0200)
application/Sidebar.c
application/Sidebar.h
application/SidebarP.h
application/player.c
application/playlist.c
application/playlist.h
application/window.c
application/window.h

index d6b3ff4521244e32d792eb8f9de4014192be8d90..4faff71308150ce2f5d60cfc3b9ad0a9b449e4a6 100644 (file)
@@ -43,9 +43,10 @@ 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 void xdndEnterAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
+static void FocusInAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
+static void SelectElmAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
+static void PopupAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
 
 static void sidebar_xdnd_callback(Widget w, XtPointer udata, XtPointer cdata);
 
@@ -56,12 +57,13 @@ static XtResource resources[] = {
 
 static XtActionsRec actionslist[] = {
   {"focusIn", FocusInAP},
-  {"xdnd_enter", xdndEnterAP},
-  {"NULL", NULL}
+  {"selectElm", SelectElmAP},
+  {"popup", PopupAP}
 };
 
-static char defaultTranslations[] = "<FocusIn>:                        focusIn()\n"
-                                    "<Message>XdndEnter:    xdnd_enter()\n";
+static char defaultTranslations[] = "<FocusIn>:  focusIn()\n"
+                                    "<Btn1Down>: selectElm()\n"
+                                    "<Btn3Down>: popup()";
 
 
 static XtResource constraints[] = {};
@@ -156,6 +158,8 @@ static void sidebar_class_part_init (WidgetClass wc) {
 static void sidebar_init(Widget request, Widget neww, ArgList args, Cardinal *num_args) {
     Sidebar sb = (Sidebar)neww;
     
+    // initialize everything except XftDraw or other stuff that needs a Window
+    
     XftColor fg, bg;
     fg.color.red = 0;
     fg.color.green = 0;
@@ -175,6 +179,11 @@ static void sidebar_init(Widget request, Widget neww, ArgList args, Cardinal *nu
         fprintf(stderr, "Cannot open font.\nAbort.\n");
         exit(-1);
     }
+    
+    XftFont *xftFont = sb->sidebar.font->fonts->font;
+    int padding = 2;
+    int fontheight = xftFont->ascent;
+    sb->sidebar.elmHeight = fontheight + 2*padding;
 }
 
 
@@ -216,17 +225,20 @@ static void sidebar_realize(Widget widget, XtValueMask *mask, XSetWindowAttribut
 }
 
 static void sidebar_expose(Widget widget, XEvent *event, Region        region) {
-    printf("expose\n");
+    //printf("expose\n");
     Dimension w, h;
     XtMakeResizeRequest(widget, 200, 200, &w, &h);
     
     Sidebar s = (Sidebar)widget;
+    XftFont *xftFont = s->sidebar.font->fonts->font;
+    
     
     XftDrawRect(s->sidebar.d, &s->sidebar.bg, 0, 0, s->core.width, s->core.height);
     
-    int height = 20;
+    int fontheight = xftFont->ascent;
+    int height = s->sidebar.elmHeight;
     
-    printf("current track: %d\n", s->sidebar.window->playlist.current_track);
+    //printf("current track: %d\n", s->sidebar.window->playlist.current_track);
     
     int i = 0;
     UCX_FOREACH(elm, s->sidebar.window->playlist.tracks) {
@@ -237,7 +249,7 @@ static void sidebar_expose(Widget widget, XEvent *event, Region     region) {
             cg = &s->sidebar.bg;
         }
         
-        XftDrawString8(s->sidebar.d, cg, s->sidebar.font->fonts->font, 10, i*height + 15, (const FcChar8*)name, strlen(name));
+        XftDrawString8(s->sidebar.d, cg, s->sidebar.font->fonts->font, 10, i*height + xftFont->ascent, (const FcChar8*)name, strlen(name));
         
         i++;
     }
@@ -259,15 +271,23 @@ Boolean sidebar_acceptfocus(Widget widget, Time *time) {
 
 
 static void FocusInAP(Widget w, XEvent *event, String *args, Cardinal *nArgs) {
-    printf("focusin\n");
-    fflush(stdout);
+    
 }
 
-static void xdndEnterAP(Widget w, XEvent *event, String *args, Cardinal *nArgs) {
-    printf("xdndEnterAP\n");
-    fflush(stdout);
+static void SelectElmAP(Widget w, XEvent *event, String *args, Cardinal *nArgs) {
+    //printf("btn1\n");
+    XButtonEvent *e = &event->xbutton;
+    Sidebar s = (Sidebar)w;
+    
+    int selected = e->y / s->sidebar.elmHeight;
+    PlayListPlayTrack(s->sidebar.window, selected);
+    
+    SidebarRepaint(w);
 }
 
+static void PopupAP(Widget w, XEvent *event, String *args, Cardinal *nArgs) {
+    //printf("btn3\n");
+}
 
 
 
@@ -345,3 +365,7 @@ void SidebarSetWindow(Widget widget, MainWindow *win) {
     Sidebar sb = (Sidebar)widget;
     sb->sidebar.window = win;
 }
+
+void SidebarRepaint(Widget widget) {
+    XClearArea(XtDisplay(widget), XtWindow(widget), 0, 0, widget->core.width, widget->core.height, true);
+}
index 2109bc88c3d1287be0e73f792a7ff389da3e9027..96a758695c0b84d467ff05cb1d8b29fb628b3775 100644 (file)
@@ -40,6 +40,8 @@ Widget CreateSidebar(
 
 void SidebarSetWindow(Widget widget, MainWindow *win);
 
+void SidebarRepaint(Widget widget);
+
 
 #ifdef __cplusplus
 }
index 6ff771e00084bb82c7e83ef74dbae4c696f2741f..c483a90681d57c63ec75a645afa92ee076246c2a 100644 (file)
@@ -58,6 +58,8 @@ typedef struct SidebarPart {
     XftColor fg;
     XftColor bg;
     
+    int elmHeight;
+    
     MainWindow *window;
 } SidebarPart;
 
index 42f09e740c3cd859fe9c12c704757125a1406b49..be4d77f96ada34be88771d364e7efb41df792d09 100644 (file)
@@ -242,6 +242,11 @@ static int connect_to_ipc(Player *player) {
     return 0;
 }
 
+static Boolean update_player_window(XtPointer data) {
+    MainWindow *win = data;
+    WindowUpdate(win);
+}
+
 static void* start_player(void *data) {
     MainWindow *win = data;
     
@@ -272,6 +277,9 @@ static void* start_player(void *data) {
     }
     win->player = player;
     
+    // update main window
+    AppExecProc(update_player_window, win);
+    
     // IO
     player_io(player);
     
index 06172c3e2dbc9e42671839b48ff6ea68e00ec6ce..80d335bd914f8b05217eff8c9b9de38490771e88 100644 (file)
@@ -54,13 +54,18 @@ void PlayListPlayNext(MainWindow *win, bool force) {
         current = 0;
     }
     
-    win->playlist.current_track = current;
-    
-    UcxList *fileElm = ucx_list_get(tracks, current);
-    if(!fileElm) {
-        return;
+    PlayListPlayTrack(win, current);
+}
+
+void PlayListPlayTrack(MainWindow *win, int i) {
+    UcxList *tracks = win->playlist.tracks;
+    if(i < ucx_list_size(tracks)) {
+        win->playlist.current_track = i;
+        UcxList *fileElm = ucx_list_get(tracks, i);
+        if(fileElm) {
+            win->file = fileElm->data;
+            PlayerOpenFile(win);
+            win->playlist.current_track = i;
+        }
     }
-    win->file = fileElm->data;
-    
-    PlayerOpenFile(win);
 }
index abb4e628c5744f6046d7c98d5ca21f5665b33700..5e1a0b8efa3ad7f53d62c9b30bd287236f4d954a 100644 (file)
@@ -35,6 +35,8 @@ void PlayListAddFile(MainWindow *win, const char *file);
 
 void PlayListPlayNext(MainWindow *win, bool force);
 
+void PlayListPlayTrack(MainWindow *win, int i);
+
 #ifdef __cplusplus
 }
 #endif
index eb6335a9ae0aa782d54f439afbca3ce2e585e785..1b351a8b67c2d0d998c379d06954ae127f32bdf3 100644 (file)
@@ -698,7 +698,6 @@ void WindowShowSidebar(MainWindow *win) {
     XtVaSetValues(win->player_widget, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, win->sidebar, NULL);
 }
 
-
-
-
-
+void WindowUpdate(MainWindow *win) {
+    SidebarRepaint(win->sidebar);
+}
index 617ff7146e8be57f0c6e7dd17d0870aace529e23..c00f29e19ca289ddc1d14951e3f9466209421733 100644 (file)
@@ -109,6 +109,8 @@ void WindowHandlePlayerEvent(MainWindow *win, XEvent *event);
 void WindowHideSidebar(MainWindow *win);
 void WindowShowSidebar(MainWindow *win);
 
+void WindowUpdate(MainWindow *win);
+
 
 #ifdef __cplusplus
 }