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);
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[] = {};
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;
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;
}
}
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) {
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++;
}
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");
+}
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);
+}