From 12ab477aa578d7d1832e3ef53ea013962af60415 Mon Sep 17 00:00:00 2001 From: Oleksiy Yakovenko Date: Wed, 27 Dec 2023 18:03:48 +0100 Subject: [PATCH] gtkui: forward key-press event from ddbtabstrip to mainwin handler (fixes #3026) --- plugins/gtkui/ddbtabstrip.c | 779 +++++++++++++++++++++--------------- 1 file changed, 451 insertions(+), 328 deletions(-) diff --git a/plugins/gtkui/ddbtabstrip.c b/plugins/gtkui/ddbtabstrip.c index 1617a8e05d..8cc88fcdbb 100644 --- a/plugins/gtkui/ddbtabstrip.c +++ b/plugins/gtkui/ddbtabstrip.c @@ -32,21 +32,23 @@ #include "interface.h" #include "playlist/mainplaylist.h" #include "support.h" +#include "callbacks.h" -#define GLADE_HOOKUP_OBJECT(component,widget,name) \ - g_object_set_data_full (G_OBJECT (component), name, \ - g_object_ref (G_OBJECT (widget)), (GDestroyNotify) g_object_unref) - -#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \ - g_object_set_data (G_OBJECT (component), name, widget) +#define GLADE_HOOKUP_OBJECT(component, widget, name) \ + g_object_set_data_full ( \ + G_OBJECT (component), \ + name, \ + g_object_ref (G_OBJECT (widget)), \ + (GDestroyNotify)g_object_unref) +#define GLADE_HOOKUP_OBJECT_NO_REF(component, widget, name) g_object_set_data (G_OBJECT (component), name, widget) G_DEFINE_TYPE (DdbTabStrip, ddb_tabstrip, GTK_TYPE_WIDGET); extern GtkWidget *theme_button; #define arrow_sz (ts->calculated_arrow_width) -#define arrow_widget_width (arrow_sz+4) -#define add_playlist_btn_width arrow_widget_width*2 +#define arrow_widget_width (arrow_sz + 4) +#define add_playlist_btn_width arrow_widget_width * 2 enum { INFO_TARGET_URIS, // gtk sets this to 0 by default @@ -70,14 +72,13 @@ plt_get_title_wrapper (int plt, char *buffer, int len) { } static void -ddb_tabstrip_send_configure (DdbTabStrip *darea) -{ +ddb_tabstrip_send_configure (DdbTabStrip *darea) { GtkWidget *widget; GdkEvent *event = gdk_event_new (GDK_CONFIGURE); widget = GTK_WIDGET (darea); - event->configure.window = g_object_ref (gtk_widget_get_window(widget)); + event->configure.window = g_object_ref (gtk_widget_get_window (widget)); event->configure.send_event = TRUE; GtkAllocation a; @@ -97,12 +98,10 @@ ddb_tabstrip_realize (GtkWidget *widget) { GdkWindowAttr attributes; gint attributes_mask; - if (!gtk_widget_get_has_window (widget)) - { + if (!gtk_widget_get_has_window (widget)) { GTK_WIDGET_CLASS (ddb_tabstrip_parent_class)->realize (widget); } - else - { + else { gtk_widget_set_realized (widget, TRUE); gtk_widget_set_can_focus (widget, TRUE); @@ -115,23 +114,23 @@ ddb_tabstrip_realize (GtkWidget *widget) { attributes.height = a.height; attributes.wclass = GDK_INPUT_OUTPUT; attributes.visual = gtk_widget_get_visual (widget); -#if !GTK_CHECK_VERSION(3,0,0) +#if !GTK_CHECK_VERSION(3, 0, 0) attributes.colormap = gtk_widget_get_colormap (widget); #endif attributes.event_mask = gtk_widget_get_events (widget); - attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_KEY_PRESS_MASK | - GDK_LEAVE_NOTIFY_MASK; + attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | + GDK_POINTER_MOTION_MASK | GDK_KEY_PRESS_MASK | GDK_LEAVE_NOTIFY_MASK; attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL; -#if !GTK_CHECK_VERSION(3,0,0) +#if !GTK_CHECK_VERSION(3, 0, 0) attributes_mask |= GDK_WA_COLORMAP; #endif GdkWindow *window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); - gtk_widget_set_window(widget, window); - gdk_window_set_user_data (gtk_widget_get_window(widget), darea); + gtk_widget_set_window (widget, window); + gdk_window_set_user_data (gtk_widget_get_window (widget), darea); -#if !GTK_CHECK_VERSION(3,0,0) +#if !GTK_CHECK_VERSION(3, 0, 0) widget->style = gtk_style_attach (widget->style, widget->window); gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); #else @@ -141,189 +140,166 @@ ddb_tabstrip_realize (GtkWidget *widget) { ddb_tabstrip_send_configure (DDB_TABSTRIP (widget)); GtkTargetEntry entries[] = { - { - .target = TARGET_PLAYLIST_AND_ITEM_INDEXES, - .flags = GTK_TARGET_SAME_APP, - .info = INFO_TARGET_PLAYLIST_ITEM_INDEXES - }, - { - .target = TARGET_PLAYITEM_POINTERS, - .flags = GTK_TARGET_SAME_APP, - .info = INFO_TARGET_PLAYITEM_POINTERS - }, + {.target = TARGET_PLAYLIST_AND_ITEM_INDEXES, + .flags = GTK_TARGET_SAME_APP, + .info = INFO_TARGET_PLAYLIST_ITEM_INDEXES }, + { .target = TARGET_PLAYITEM_POINTERS, .flags = GTK_TARGET_SAME_APP, .info = INFO_TARGET_PLAYITEM_POINTERS}, }; - gtk_drag_dest_set (widget, GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP, entries, 2, GDK_ACTION_COPY | GDK_ACTION_MOVE); + gtk_drag_dest_set ( + widget, + GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP, + entries, + 2, + GDK_ACTION_COPY | GDK_ACTION_MOVE); gtk_drag_dest_add_uri_targets (widget); gtk_drag_dest_set_track_motion (widget, TRUE); } static void -ddb_tabstrip_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - g_return_if_fail (DDB_IS_TABSTRIP (widget)); - g_return_if_fail (allocation != NULL); - - gtk_widget_set_allocation (widget, allocation); - - if (gtk_widget_get_realized (widget)) - { - if (gtk_widget_get_has_window (widget)) - gdk_window_move_resize (gtk_widget_get_window(widget), - allocation->x, allocation->y, - allocation->width, allocation->height); - - ddb_tabstrip_send_configure (DDB_TABSTRIP (widget)); +ddb_tabstrip_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { + g_return_if_fail (DDB_IS_TABSTRIP (widget)); + g_return_if_fail (allocation != NULL); + + gtk_widget_set_allocation (widget, allocation); + + if (gtk_widget_get_realized (widget)) { + if (gtk_widget_get_has_window (widget)) + gdk_window_move_resize ( + gtk_widget_get_window (widget), + allocation->x, + allocation->y, + allocation->width, + allocation->height); + + ddb_tabstrip_send_configure (DDB_TABSTRIP (widget)); } } - gboolean -on_tabstrip_scroll_event (GtkWidget *widget, - GdkEventScroll *event); +on_tabstrip_scroll_event (GtkWidget *widget, GdkEventScroll *event); gboolean -on_tabstrip_button_press_event (GtkWidget *widget, - GdkEventButton *event); +on_tabstrip_button_press_event (GtkWidget *widget, GdkEventButton *event); gboolean -on_tabstrip_button_release_event (GtkWidget *widget, - GdkEventButton *event); +on_tabstrip_button_release_event (GtkWidget *widget, GdkEventButton *event); gboolean -on_tabstrip_configure_event (GtkWidget *widget, - GdkEventConfigure *event); +on_tabstrip_configure_event (GtkWidget *widget, GdkEventConfigure *event); gboolean -on_tabstrip_draw (GtkWidget *widget, - cairo_t *cr); - +on_tabstrip_draw (GtkWidget *widget, cairo_t *cr); gboolean -on_tabstrip_expose_event (GtkWidget *widget, - GdkEventExpose *event); +on_tabstrip_expose_event (GtkWidget *widget, GdkEventExpose *event); gboolean -on_tabstrip_motion_notify_event (GtkWidget *widget, - GdkEventMotion *event); +on_tabstrip_motion_notify_event (GtkWidget *widget, GdkEventMotion *event); gboolean -on_tabstrip_drag_motion_event (GtkWidget *widget, - GdkDragContext *drag_context, - gint x, - gint y, - guint time); +on_tabstrip_drag_motion_event (GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y, guint time); gboolean -on_tabstrip_drag_drop (GtkWidget *widget, - GdkDragContext *drag_context, - gint x, - gint y, - guint time); +on_tabstrip_drag_drop (GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y, guint time); void -on_tabstrip_drag_data_received (GtkWidget *widget, - GdkDragContext *drag_context, - gint x, - gint y, - GtkSelectionData *data, - guint target_type, - guint time); +on_tabstrip_drag_data_received ( + GtkWidget *widget, + GdkDragContext *drag_context, + gint x, + gint y, + GtkSelectionData *data, + guint target_type, + guint time); void -on_tabstrip_drag_leave (GtkWidget *widget, - GdkDragContext *drag_context, - guint time); +on_tabstrip_drag_leave (GtkWidget *widget, GdkDragContext *drag_context, guint time); void -on_tabstrip_drag_end (GtkWidget *widget, - GdkDragContext *drag_context); +on_tabstrip_drag_end (GtkWidget *widget, GdkDragContext *drag_context); gboolean -on_tabstrip_key_press_event (GtkWidget *widget, - GdkEventKey *event); +on_tabstrip_key_press_event (GtkWidget *widget, GdkEventKey *event); static int get_tab_under_cursor (DdbTabStrip *ts, int x); static void -ddb_tabstrip_unrealize(GtkWidget *w) -{ - DdbTabStrip *tabstrip; +ddb_tabstrip_unrealize (GtkWidget *w) { + DdbTabStrip *tabstrip; - g_return_if_fail(w != NULL); - g_return_if_fail(DDB_IS_TABSTRIP(w)); + g_return_if_fail (w != NULL); + g_return_if_fail (DDB_IS_TABSTRIP (w)); - tabstrip = DDB_TABSTRIP (w); - draw_free (&tabstrip->drawctx); - GTK_WIDGET_CLASS (ddb_tabstrip_parent_class)->unrealize (w); + tabstrip = DDB_TABSTRIP (w); + draw_free (&tabstrip->drawctx); + GTK_WIDGET_CLASS (ddb_tabstrip_parent_class)->unrealize (w); } gboolean on_tabstrip_leave_notify_event (GtkWidget *, GdkEventCrossing *); static void -ddb_tabstrip_class_init(DdbTabStripClass *class) -{ - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); -#if !GTK_CHECK_VERSION(3,0,0) - widget_class->expose_event = on_tabstrip_expose_event; +ddb_tabstrip_class_init (DdbTabStripClass *class) { + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); +#if !GTK_CHECK_VERSION(3, 0, 0) + widget_class->expose_event = on_tabstrip_expose_event; #else - widget_class->draw = on_tabstrip_draw; + widget_class->draw = on_tabstrip_draw; #endif - widget_class->realize = ddb_tabstrip_realize; - widget_class->unrealize = ddb_tabstrip_unrealize; - widget_class->size_allocate = ddb_tabstrip_size_allocate; - widget_class->button_press_event = on_tabstrip_button_press_event; - widget_class->button_release_event = on_tabstrip_button_release_event; - widget_class->configure_event = on_tabstrip_configure_event; - widget_class->motion_notify_event = on_tabstrip_motion_notify_event; - widget_class->scroll_event= on_tabstrip_scroll_event; - widget_class->drag_motion = on_tabstrip_drag_motion_event; - widget_class->drag_drop = on_tabstrip_drag_drop; - widget_class->drag_end = on_tabstrip_drag_end; - widget_class->drag_data_received = on_tabstrip_drag_data_received; - widget_class->drag_leave = on_tabstrip_drag_leave; - widget_class->key_press_event = on_tabstrip_key_press_event; - widget_class->leave_notify_event = on_tabstrip_leave_notify_event; + widget_class->realize = ddb_tabstrip_realize; + widget_class->unrealize = ddb_tabstrip_unrealize; + widget_class->size_allocate = ddb_tabstrip_size_allocate; + widget_class->button_press_event = on_tabstrip_button_press_event; + widget_class->button_release_event = on_tabstrip_button_release_event; + widget_class->configure_event = on_tabstrip_configure_event; + widget_class->motion_notify_event = on_tabstrip_motion_notify_event; + widget_class->scroll_event = on_tabstrip_scroll_event; + widget_class->drag_motion = on_tabstrip_drag_motion_event; + widget_class->drag_drop = on_tabstrip_drag_drop; + widget_class->drag_end = on_tabstrip_drag_end; + widget_class->drag_data_received = on_tabstrip_drag_data_received; + widget_class->drag_leave = on_tabstrip_drag_leave; + widget_class->key_press_event = on_tabstrip_key_press_event; + widget_class->leave_notify_event = on_tabstrip_leave_notify_event; } gboolean -on_tabstrip_drag_drop (GtkWidget *widget, - GdkDragContext *drag_context, - gint x, - gint y, - guint time) -{ +on_tabstrip_drag_drop (GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y, guint time) { return TRUE; } void -on_tabstrip_drag_data_received (GtkWidget *widget, - GdkDragContext *drag_context, - gint x, - gint y, - GtkSelectionData *data, - guint target_type, - guint time) -{ - gchar *ptr=(char*)gtk_selection_data_get_data (data); +on_tabstrip_drag_data_received ( + GtkWidget *widget, + GdkDragContext *drag_context, + gint x, + gint y, + GtkSelectionData *data, + guint target_type, + guint time) { + gchar *ptr = (char *)gtk_selection_data_get_data (data); int len = gtk_selection_data_get_length (data); if (target_type == INFO_TARGET_URIS) { // uris // this happens when dropped from file manager - char *mem = malloc (len+1); + char *mem = malloc (len + 1); memcpy (mem, ptr, len); mem[len] = 0; // we don't pass control structure, but there's only one drag-drop view currently gtkui_receive_fm_drop (NULL, mem, len); } else if (target_type == INFO_TARGET_PLAYLIST_ITEM_INDEXES) { - uint32_t *d= (uint32_t *)ptr; + uint32_t *d = (uint32_t *)ptr; int plt = *d; d++; - int length = (len/4)-1; + int length = (len / 4) - 1; ddb_playlist_t *p = deadbeef->plt_get_for_idx (plt); if (p) { - main_drag_n_drop (NULL, p, d, length, gdk_drag_context_get_selected_action (drag_context) == GDK_ACTION_COPY ? 1 : 0); + main_drag_n_drop ( + NULL, + p, + d, + length, + gdk_drag_context_get_selected_action (drag_context) == GDK_ACTION_COPY ? 1 : 0); deadbeef->plt_unref (p); } } @@ -334,29 +310,24 @@ on_tabstrip_drag_data_received (GtkWidget *widget, } void -on_tabstrip_drag_leave (GtkWidget *widget, - GdkDragContext *drag_context, - guint time) -{ - DdbTabStrip *ts = DDB_TABSTRIP(widget); +on_tabstrip_drag_leave (GtkWidget *widget, GdkDragContext *drag_context, guint time) { + DdbTabStrip *ts = DDB_TABSTRIP (widget); if (ts->pick_drag_timer != 0) { - g_source_remove(ts->pick_drag_timer); + g_source_remove (ts->pick_drag_timer); } } void -on_tabstrip_drag_end (GtkWidget *widget, - GdkDragContext *drag_context) -{ +on_tabstrip_drag_end (GtkWidget *widget, GdkDragContext *drag_context) { } -GtkWidget * ddb_tabstrip_new(void) { +GtkWidget * +ddb_tabstrip_new (void) { return g_object_new (DDB_TYPE_TABSTRIP, NULL); } static void -ddb_tabstrip_init(DdbTabStrip *tabstrip) -{ +ddb_tabstrip_init (DdbTabStrip *tabstrip) { tabstrip->hscrollpos = 0; tabstrip->dragging = -1; tabstrip->prepare = 0; @@ -365,8 +336,10 @@ ddb_tabstrip_init(DdbTabStrip *tabstrip) tabstrip->prev_x = 0; tabstrip->movepos = 0; drawctx_init (&tabstrip->drawctx); -#if GTK_CHECK_VERSION(3,0,0) - gtk_widget_set_events (GTK_WIDGET (tabstrip), gtk_widget_get_events (GTK_WIDGET (tabstrip)) | GDK_SCROLL_MASK | GDK_KEY_PRESS_MASK); +#if GTK_CHECK_VERSION(3, 0, 0) + gtk_widget_set_events ( + GTK_WIDGET (tabstrip), + gtk_widget_get_events (GTK_WIDGET (tabstrip)) | GDK_SCROLL_MASK | GDK_KEY_PRESS_MASK); #endif } @@ -382,19 +355,19 @@ static int max_tab_size = 200; static int tab_moved = 0; typedef struct { -#if GTK_CHECK_VERSION(3,0,0) +#if GTK_CHECK_VERSION(3, 0, 0) float x, y; #else int x, y; #endif } coord_t; -#if GTK_CHECK_VERSION(3,0,0) +#if GTK_CHECK_VERSION(3, 0, 0) static void cairo_draw_lines (cairo_t *cr, coord_t *pts, int cnt) { - cairo_move_to (cr, pts[0].x+1, pts[0].y+1); + cairo_move_to (cr, pts[0].x + 1, pts[0].y + 1); for (int i = 1; i < cnt; i++) { - cairo_line_to (cr, pts[i].x+1, pts[i].y+1); + cairo_line_to (cr, pts[i].x + 1, pts[i].y + 1); } } @@ -408,40 +381,58 @@ cairo_draw_poly (cairo_t *cr, coord_t *pts, int cnt) { #endif void -#if !GTK_CHECK_VERSION(3,0,0) -ddb_tabstrip_draw_tab (GtkWidget *widget, GdkDrawable *drawable, int idx, int selected, int x, int y, int w, int h, GtkStyle *style) { +#if !GTK_CHECK_VERSION(3, 0, 0) +ddb_tabstrip_draw_tab ( + GtkWidget *widget, + GdkDrawable *drawable, + int idx, + int selected, + int x, + int y, + int w, + int h, + GtkStyle *style) { #else -ddb_tabstrip_draw_tab (GtkWidget *widget, cairo_t *cr, int idx, int selected, int x, int y, int w, int h, GtkStyle *style) { +ddb_tabstrip_draw_tab ( + GtkWidget *widget, + cairo_t *cr, + int idx, + int selected, + int x, + int y, + int w, + int h, + GtkStyle *style) { #endif coord_t points_filled[] = { - { x+2, y + h }, - { x+2, y + 2 }, - { x + w - h + 1, y + 2 }, - { x + w - 1 + 1, y + h } + {x + 2, y + h}, + { x + 2, y + 2}, + { x + w - h + 1, y + 2}, + { x + w - 1 + 1, y + h} }; coord_t points_frame1[] = { - { x, y + h-2 }, -#if GTK_CHECK_VERSION(3,0,0) - { x, y + 0.5 }, - { x + 0.5, y }, + {x, y + h - 2}, +#if GTK_CHECK_VERSION(3, 0, 0) + { x, y + 0.5 }, + { x + 0.5, y }, #else { x, y + 1 }, { x + 1, y }, #endif - { x + w - h - 1, y }, - { x + w - h + 1, y + 1 }, - { x + w - 3, y + h - 3 }, - { x + w - 0, y + h - 2 }, + { x + w - h - 1, y }, + { x + w - h + 1, y + 1 }, + { x + w - 3, y + h - 3}, + { x + w - 0, y + h - 2}, }; coord_t points_frame2[] = { - { x + 1, y + h -1 }, - { x + 1, y + 1 }, - { x + w - h - 1, y + 1 }, - { x + w - h + 1, y + 2 }, - { x + w - 3, y + h - 2 }, - { x + w - 0, y + h - 1 }, + {x + 1, y + h - 1}, + { x + 1, y + 1 }, + { x + w - h - 1, y + 1 }, + { x + w - h + 1, y + 2 }, + { x + w - 3, y + h - 2}, + { x + w - 0, y + h - 1}, }; -#if !GTK_CHECK_VERSION(3,0,0) +#if !GTK_CHECK_VERSION(3, 0, 0) GdkGC *bg = gdk_gc_new (drawable); GdkGC *outer_frame = gdk_gc_new (drawable); GdkGC *inner_frame = gdk_gc_new (drawable); @@ -469,14 +460,16 @@ ddb_tabstrip_draw_tab (GtkWidget *widget, cairo_t *cr, int idx, int selected, in if (fallback) { if (theming) { clr_bg = style->bg[GTK_STATE_NORMAL]; - } else { + } + else { gtkui_get_tabstrip_base_color (&clr_bg); } } if (theming) { clr_outer_frame = style->dark[GTK_STATE_NORMAL]; clr_inner_frame = style->light[GTK_STATE_NORMAL]; - } else { + } + else { gtkui_get_tabstrip_dark_color (&clr_outer_frame); gtkui_get_tabstrip_light_color (&clr_inner_frame); } @@ -485,40 +478,50 @@ ddb_tabstrip_draw_tab (GtkWidget *widget, cairo_t *cr, int idx, int selected, in if (fallback) { if (theming) { clr_bg = style->mid[GTK_STATE_NORMAL]; - } else { + } + else { gtkui_get_tabstrip_mid_color (&clr_bg); } } if (theming) { clr_outer_frame = style->dark[GTK_STATE_NORMAL]; clr_inner_frame = style->mid[GTK_STATE_NORMAL]; - } else { + } + else { gtkui_get_tabstrip_dark_color (&clr_outer_frame); gtkui_get_tabstrip_mid_color (&clr_inner_frame); } } -#if !GTK_CHECK_VERSION(3,0,0) +#if !GTK_CHECK_VERSION(3, 0, 0) gdk_gc_set_rgb_fg_color (bg, &clr_bg); gdk_gc_set_rgb_fg_color (outer_frame, &clr_outer_frame); gdk_gc_set_rgb_fg_color (inner_frame, &clr_inner_frame); - gdk_draw_polygon (drawable, bg, TRUE, (GdkPoint*)points_filled, sizeof (points_filled)/sizeof(coord_t)); - gdk_draw_lines (drawable, outer_frame, (GdkPoint*)points_frame1, sizeof (points_frame1)/sizeof(coord_t)); - gdk_draw_lines (drawable, inner_frame, (GdkPoint*)points_frame2, sizeof (points_frame2)/sizeof(coord_t)); + gdk_draw_polygon (drawable, bg, TRUE, (GdkPoint *)points_filled, sizeof (points_filled) / sizeof (coord_t)); + gdk_draw_lines (drawable, outer_frame, (GdkPoint *)points_frame1, sizeof (points_frame1) / sizeof (coord_t)); + gdk_draw_lines (drawable, inner_frame, (GdkPoint *)points_frame2, sizeof (points_frame2) / sizeof (coord_t)); g_object_unref (bg); g_object_unref (outer_frame); g_object_unref (inner_frame); #else - cairo_set_source_rgb (cr, clr_bg.red/65535.f, clr_bg.green/65535.f, clr_bg.blue/65535.0); + cairo_set_source_rgb (cr, clr_bg.red / 65535.f, clr_bg.green / 65535.f, clr_bg.blue / 65535.0); cairo_new_path (cr); - cairo_draw_poly (cr, points_filled, sizeof (points_filled)/sizeof(coord_t)); + cairo_draw_poly (cr, points_filled, sizeof (points_filled) / sizeof (coord_t)); cairo_close_path (cr); cairo_fill (cr); - cairo_set_source_rgb (cr, clr_outer_frame.red/65535.f, clr_outer_frame.green/65535.f, clr_outer_frame.blue/65535.0); - cairo_draw_lines (cr, points_frame1, sizeof (points_frame1)/sizeof(coord_t)); + cairo_set_source_rgb ( + cr, + clr_outer_frame.red / 65535.f, + clr_outer_frame.green / 65535.f, + clr_outer_frame.blue / 65535.0); + cairo_draw_lines (cr, points_frame1, sizeof (points_frame1) / sizeof (coord_t)); cairo_stroke (cr); - cairo_set_source_rgb (cr, clr_inner_frame.red/65535.f, clr_inner_frame.green/65535.f, clr_inner_frame.blue/65535.0); - cairo_draw_lines (cr, points_frame2, sizeof (points_frame2)/sizeof(coord_t)); + cairo_set_source_rgb ( + cr, + clr_inner_frame.red / 65535.f, + clr_inner_frame.green / 65535.f, + clr_inner_frame.blue / 65535.0); + cairo_draw_lines (cr, points_frame2, sizeof (points_frame2) / sizeof (coord_t)); cairo_stroke (cr); #endif } @@ -549,7 +552,7 @@ tabstrip_need_arrows (DdbTabStrip *ts) { gtk_widget_get_allocation (widget, &a); for (int idx = 0; idx < cnt; idx++) { w += ddb_tabstrip_get_tab_width (ts, idx) - tab_overlap_size; - if (w >= a.width-add_playlist_btn_width-tab_overlap_size) { + if (w >= a.width - add_playlist_btn_width - tab_overlap_size) { return 1; } } @@ -567,11 +570,11 @@ tabstrip_scroll_to_tab_int (DdbTabStrip *ts, int tab, int redraw) { int cnt = deadbeef->plt_get_count (); GtkAllocation a; gtk_widget_get_allocation (widget, &a); - int tabarea_width = a.width-add_playlist_btn_width; - int boundary = tabarea_width - arrow_widget_width*2 + ts->hscrollpos; + int tabarea_width = a.width - add_playlist_btn_width; + int boundary = tabarea_width - arrow_widget_width * 2 + ts->hscrollpos; for (int idx = 0; idx < cnt; idx++) { int tab_w = ddb_tabstrip_get_tab_width (ts, idx); - if (idx == cnt-1) { + if (idx == cnt - 1) { tab_w += 3; } if (idx == tab) { @@ -583,7 +586,7 @@ tabstrip_scroll_to_tab_int (DdbTabStrip *ts, int tab, int redraw) { } } else if (w + tab_w >= boundary) { - ts->hscrollpos += (w+tab_w) - boundary; + ts->hscrollpos += (w + tab_w) - boundary; deadbeef->conf_set_int ("gtkui.tabscroll", ts->hscrollpos); if (redraw) { gtk_widget_queue_draw (widget); @@ -610,14 +613,14 @@ tabstrip_adjust_hscroll (DdbTabStrip *ts) { GtkAllocation a; gtk_widget_get_allocation (widget, &a); int w = 0; - int tabarea_width = a.width-add_playlist_btn_width; + int tabarea_width = a.width - add_playlist_btn_width; int cnt = deadbeef->plt_get_count (); for (int idx = 0; idx < cnt; idx++) { w += ddb_tabstrip_get_tab_width (ts, idx) - tab_overlap_size; } w += tab_overlap_size + 3; - if (ts->hscrollpos > w - (tabarea_width - arrow_widget_width*2)) { - ts->hscrollpos = w - (tabarea_width - arrow_widget_width*2); + if (ts->hscrollpos > w - (tabarea_width - arrow_widget_width * 2)) { + ts->hscrollpos = w - (tabarea_width - arrow_widget_width * 2); deadbeef->conf_set_int ("gtkui.tabscroll", ts->hscrollpos); } tabstrip_scroll_to_tab_int (ts, deadbeef->plt_get_curr_idx (), 0); @@ -642,7 +645,7 @@ set_tab_text_color (DdbTabStrip *ts, int idx, int selected, int playing, GtkStyl int r, g, b; if (3 == sscanf (clr, "%02x%02x%02x", &r, &g, &b)) { fallback = 0; - float fg[3] = {(float)r/0xff, (float)g/0xff, (float)b/0xff}; + float fg[3] = { (float)r / 0xff, (float)g / 0xff, (float)b / 0xff }; draw_set_fg_color (&ts->drawctx, fg); } } @@ -663,7 +666,7 @@ set_tab_text_color (DdbTabStrip *ts, int idx, int selected, int playing, GtkStyl else { color = style->text[GTK_STATE_NORMAL]; } - float fg[3] = {(float)color.red/0xffff, (float)color.green/0xffff, (float)color.blue/0xffff}; + float fg[3] = { (float)color.red / 0xffff, (float)color.green / 0xffff, (float)color.blue / 0xffff }; draw_set_fg_color (&ts->drawctx, fg); } deadbeef->pl_unlock (); @@ -672,7 +675,7 @@ set_tab_text_color (DdbTabStrip *ts, int idx, int selected, int playing, GtkStyl void tabstrip_render (DdbTabStrip *ts, cairo_t *cr) { GtkWidget *widget = GTK_WIDGET (ts); -#if !GTK_CHECK_VERSION(3,0,0) +#if !GTK_CHECK_VERSION(3, 0, 0) GdkDrawable *backbuf = gtk_widget_get_window (widget); #endif GtkAllocation a; @@ -695,7 +698,7 @@ tabstrip_render (DdbTabStrip *ts, cairo_t *cr) { int w = 0; int h = draw_get_font_size (&ts->drawctx); h = a.height; - tab_overlap_size = (h-4)/2; + tab_overlap_size = (h - 4) / 2; text_right_padding = h - 3; int tab_selected = deadbeef->plt_get_curr_idx (); @@ -720,12 +723,13 @@ tabstrip_render (DdbTabStrip *ts, cairo_t *cr) { clr_mid = style->mid[GTK_STATE_NORMAL]; clr_dark = style->dark[GTK_STATE_NORMAL]; clr_base = style->base[GTK_STATE_NORMAL]; - } else { + } + else { gtkui_get_tabstrip_mid_color (&clr_mid); gtkui_get_tabstrip_dark_color (&clr_dark); gtkui_get_tabstrip_base_color (&clr_base); } -#if !GTK_CHECK_VERSION(3,0,0) +#if !GTK_CHECK_VERSION(3, 0, 0) GdkGC *gc = gdk_gc_new (backbuf); // fill background gdk_gc_set_rgb_fg_color (gc, &clr_mid); @@ -735,11 +739,11 @@ tabstrip_render (DdbTabStrip *ts, cairo_t *cr) { #else // fill background - cairo_set_source_rgb (cr, clr_mid.red/65535.f, clr_mid.green/65535.f, clr_mid.blue/65535.0); + cairo_set_source_rgb (cr, clr_mid.red / 65535.f, clr_mid.green / 65535.f, clr_mid.blue / 65535.0); cairo_rectangle (cr, 0, 0, a.width, a.height); cairo_fill (cr); - cairo_set_source_rgb (cr, clr_dark.red/65535.f, clr_dark.green/65535.f, clr_dark.blue/65535.0); + cairo_set_source_rgb (cr, clr_dark.red / 65535.f, clr_dark.green / 65535.f, clr_dark.blue / 65535.0); cairo_move_to (cr, 0, 1); cairo_line_to (cr, a.width, 1); cairo_stroke (cr); @@ -775,7 +779,7 @@ tabstrip_render (DdbTabStrip *ts, cairo_t *cr) { area.width = w; area.height = 24; if (idx != tab_selected) { -#if !GTK_CHECK_VERSION(3,0,0) +#if !GTK_CHECK_VERSION(3, 0, 0) ddb_tabstrip_draw_tab (widget, backbuf, idx, idx == tab_selected, x, y, w, h, style); #else ddb_tabstrip_draw_tab (widget, cr, idx, idx == tab_selected, x, y, w, h, style); @@ -790,22 +794,43 @@ tabstrip_render (DdbTabStrip *ts, cairo_t *cr) { italic = gtkui_tabstrip_italic_playing; bold = gtkui_tabstrip_embolden_playing; } - draw_text_custom (&ts->drawctx, x + text_left_padding, y - text_vert_offset, w - (text_left_padding + text_right_padding - 1), 0, DDB_TABSTRIP_FONT, bold, italic, tab_title); + draw_text_custom ( + &ts->drawctx, + x + text_left_padding, + y - text_vert_offset, + w - (text_left_padding + text_right_padding - 1), + 0, + DDB_TABSTRIP_FONT, + bold, + italic, + tab_title); } x += w - tab_overlap_size; } -#if !GTK_CHECK_VERSION(3,0,0) - gdk_draw_line (backbuf, style->dark_gc[GTK_STATE_NORMAL], 0, widget->allocation.height-2, widget->allocation.width, widget->allocation.height-2); - gdk_draw_line (backbuf, style->light_gc[GTK_STATE_NORMAL], 0, widget->allocation.height-1, widget->allocation.width, widget->allocation.height-1); +#if !GTK_CHECK_VERSION(3, 0, 0) + gdk_draw_line ( + backbuf, + style->dark_gc[GTK_STATE_NORMAL], + 0, + widget->allocation.height - 2, + widget->allocation.width, + widget->allocation.height - 2); + gdk_draw_line ( + backbuf, + style->light_gc[GTK_STATE_NORMAL], + 0, + widget->allocation.height - 1, + widget->allocation.width, + widget->allocation.height - 1); #else GdkColor *pclr = &style->dark[GTK_STATE_NORMAL]; - cairo_set_source_rgb (cr, pclr->red/65535.f, pclr->green/65535.f, pclr->blue/65535.0); - cairo_move_to (cr, 0, a.height-1); - cairo_line_to (cr, a.width, a.height-1); + cairo_set_source_rgb (cr, pclr->red / 65535.f, pclr->green / 65535.f, pclr->blue / 65535.0); + cairo_move_to (cr, 0, a.height - 1); + cairo_line_to (cr, a.width, a.height - 1); cairo_stroke (cr); pclr = &style->light[GTK_STATE_NORMAL]; - cairo_set_source_rgb (cr, pclr->red/65535.f, pclr->green/65535.f, pclr->blue/65535.0); + cairo_set_source_rgb (cr, pclr->red / 65535.f, pclr->green / 65535.f, pclr->blue / 65535.0); cairo_move_to (cr, 0, a.height); cairo_line_to (cr, a.width, a.height); cairo_stroke (cr); @@ -825,7 +850,7 @@ tabstrip_render (DdbTabStrip *ts, cairo_t *cr) { area.y = 0; area.width = w; area.height = 24; -#if !GTK_CHECK_VERSION(3,0,0) +#if !GTK_CHECK_VERSION(3, 0, 0) ddb_tabstrip_draw_tab (widget, backbuf, idx, 1, x, y, w, h, style); #else ddb_tabstrip_draw_tab (widget, cr, idx, 1, x, y, w, h, style); @@ -840,18 +865,33 @@ tabstrip_render (DdbTabStrip *ts, cairo_t *cr) { italic = gtkui_tabstrip_italic_selected; } if (gtk_widget_is_focus (GTK_WIDGET (ts))) { -#if GTK_CHECK_VERSION(3,0,0) - gtk_render_focus (gtk_widget_get_style_context (widget), cr, x, y, w - ( text_right_padding - 1), ts->row_height); +#if GTK_CHECK_VERSION(3, 0, 0) + gtk_render_focus ( + gtk_widget_get_style_context (widget), + cr, + x, + y, + w - (text_right_padding - 1), + ts->row_height); #else GdkColor clr; gtkui_get_tabstrip_text_color (&clr); gdk_gc_set_rgb_fg_color (gc, &clr); gdk_gc_set_line_attributes (gc, 1, GDK_LINE_ON_OFF_DASH, GDK_CAP_BUTT, GDK_JOIN_BEVEL); - gdk_gc_set_dashes (gc, 0, (gint8[]) {1,1}, 2); - gdk_draw_rectangle (backbuf, gc, FALSE, x, y , w - (text_right_padding - 1), ts->row_height-2); + gdk_gc_set_dashes (gc, 0, (gint8[]){ 1, 1 }, 2); + gdk_draw_rectangle (backbuf, gc, FALSE, x, y, w - (text_right_padding - 1), ts->row_height - 2); #endif } - draw_text_custom (&ts->drawctx, x + text_left_padding, y - text_vert_offset, w - (text_left_padding + text_right_padding - 1), 0, DDB_TABSTRIP_FONT, bold, italic, tab_title); + draw_text_custom ( + &ts->drawctx, + x + text_left_padding, + y - text_vert_offset, + w - (text_left_padding + text_right_padding - 1), + 0, + DDB_TABSTRIP_FONT, + bold, + italic, + tab_title); } else { need_draw_moving = 1; @@ -866,7 +906,7 @@ tabstrip_render (DdbTabStrip *ts, cairo_t *cr) { break; } if (w > 0) { -#if !GTK_CHECK_VERSION(3,0,0) +#if !GTK_CHECK_VERSION(3, 0, 0) ddb_tabstrip_draw_tab (widget, backbuf, idx, 1, x, y, w, h, style); #else ddb_tabstrip_draw_tab (widget, cr, idx, 1, x, y, w, h, style); @@ -880,7 +920,16 @@ tabstrip_render (DdbTabStrip *ts, cairo_t *cr) { bold = gtkui_tabstrip_embolden_selected; italic = gtkui_tabstrip_italic_selected; } - draw_text_custom (&ts->drawctx, x + text_left_padding, y - text_vert_offset, w - (text_left_padding + text_right_padding - 1), 0, DDB_TABSTRIP_FONT, bold, italic, tab_title); + draw_text_custom ( + &ts->drawctx, + x + text_left_padding, + y - text_vert_offset, + w - (text_left_padding + text_right_padding - 1), + 0, + DDB_TABSTRIP_FONT, + bold, + italic, + tab_title); } break; } @@ -888,77 +937,176 @@ tabstrip_render (DdbTabStrip *ts, cairo_t *cr) { } } int tabarea_width = a.width - add_playlist_btn_width; -#if !GTK_CHECK_VERSION(3,0,0) +#if !GTK_CHECK_VERSION(3, 0, 0) if (need_arrows) { - int sz = widget->allocation.height-3; + int sz = widget->allocation.height - 3; gdk_gc_set_rgb_fg_color (gc, &clr_mid); gdk_draw_rectangle (backbuf, gc, TRUE, 0, 1, arrow_widget_width, sz); - gtk_paint_arrow (style, widget->window, GTK_STATE_NORMAL, GTK_SHADOW_NONE, NULL, widget, NULL, GTK_ARROW_LEFT, TRUE, 2, sz/2-arrow_sz/2, arrow_sz, arrow_sz); - gdk_draw_rectangle (backbuf, gc, TRUE, tabarea_width-arrow_widget_width, 1, arrow_widget_width, sz); - gtk_paint_arrow (style, widget->window, GTK_STATE_NORMAL, GTK_SHADOW_NONE, NULL, widget, NULL, GTK_ARROW_RIGHT, TRUE, tabarea_width-arrow_sz-2, 1+sz/2-arrow_sz/2, arrow_sz, arrow_sz); + gtk_paint_arrow ( + style, + widget->window, + GTK_STATE_NORMAL, + GTK_SHADOW_NONE, + NULL, + widget, + NULL, + GTK_ARROW_LEFT, + TRUE, + 2, + sz / 2 - arrow_sz / 2, + arrow_sz, + arrow_sz); + gdk_draw_rectangle (backbuf, gc, TRUE, tabarea_width - arrow_widget_width, 1, arrow_widget_width, sz); + gtk_paint_arrow ( + style, + widget->window, + GTK_STATE_NORMAL, + GTK_SHADOW_NONE, + NULL, + widget, + NULL, + GTK_ARROW_RIGHT, + TRUE, + tabarea_width - arrow_sz - 2, + 1 + sz / 2 - arrow_sz / 2, + arrow_sz, + arrow_sz); } #else if (need_arrows) { - int sz = a.height-3; - cairo_set_source_rgb (cr, clr_mid.red/65535.f, clr_mid.green/65535.f, clr_mid.blue/65535.0); + int sz = a.height - 3; + cairo_set_source_rgb (cr, clr_mid.red / 65535.f, clr_mid.green / 65535.f, clr_mid.blue / 65535.0); cairo_rectangle (cr, 0, 1, arrow_widget_width, sz); cairo_fill (cr); -#if GTK_CHECK_VERSION(3,0,0) - gtk_paint_arrow (style, cr, GTK_STATE_NORMAL, GTK_SHADOW_NONE, widget, NULL, GTK_ARROW_LEFT, TRUE, 2, sz/2-arrow_sz/2, arrow_sz, arrow_sz); -#else - gtk_paint_arrow (style, gtk_widget_get_window(widget), GTK_STATE_NORMAL, GTK_SHADOW_NONE, NULL, widget, NULL, GTK_ARROW_LEFT, TRUE, 2, sz/2-arrow_sz/2, arrow_sz, arrow_sz); -#endif - - cairo_rectangle (cr, tabarea_width-arrow_widget_width, 1, arrow_widget_width, sz); +# if GTK_CHECK_VERSION(3, 0, 0) + gtk_paint_arrow ( + style, + cr, + GTK_STATE_NORMAL, + GTK_SHADOW_NONE, + widget, + NULL, + GTK_ARROW_LEFT, + TRUE, + 2, + sz / 2 - arrow_sz / 2, + arrow_sz, + arrow_sz); +# else + gtk_paint_arrow ( + style, + gtk_widget_get_window (widget), + GTK_STATE_NORMAL, + GTK_SHADOW_NONE, + NULL, + widget, + NULL, + GTK_ARROW_LEFT, + TRUE, + 2, + sz / 2 - arrow_sz / 2, + arrow_sz, + arrow_sz); +# endif + + cairo_rectangle (cr, tabarea_width - arrow_widget_width, 1, arrow_widget_width, sz); cairo_fill (cr); -#if GTK_CHECK_VERSION(3,0,0) - gtk_paint_arrow (style, cr, GTK_STATE_NORMAL, GTK_SHADOW_NONE, widget, NULL, GTK_ARROW_RIGHT, TRUE, tabarea_width-arrow_sz-2, 1+sz/2-arrow_sz/2, arrow_sz, arrow_sz); -#else - gtk_paint_arrow (style, gtk_widget_get_window(widget), GTK_STATE_NORMAL, GTK_SHADOW_NONE, NULL, widget, NULL, GTK_ARROW_RIGHT, TRUE, a.width-arrow_sz-2, 1+sz/2-arrow_sz/2, arrow_sz, arrow_sz); -#endif +# if GTK_CHECK_VERSION(3, 0, 0) + gtk_paint_arrow ( + style, + cr, + GTK_STATE_NORMAL, + GTK_SHADOW_NONE, + widget, + NULL, + GTK_ARROW_RIGHT, + TRUE, + tabarea_width - arrow_sz - 2, + 1 + sz / 2 - arrow_sz / 2, + arrow_sz, + arrow_sz); +# else + gtk_paint_arrow ( + style, + gtk_widget_get_window (widget), + GTK_STATE_NORMAL, + GTK_SHADOW_NONE, + NULL, + widget, + NULL, + GTK_ARROW_RIGHT, + TRUE, + a.width - arrow_sz - 2, + 1 + sz / 2 - arrow_sz / 2, + arrow_sz, + arrow_sz); +# endif } #endif // Draw add playlist button { int playlist_button_border = 3; - int add_playlist_btn_height = a.height-playlist_button_border; + int add_playlist_btn_height = a.height - playlist_button_border; GdkColor textcolor, clr; if (ts->add_playlistbtn_hover) { clr = clr_base; if (theming) { textcolor = style->text[GTK_STATE_NORMAL]; - } else { + } + else { gtkui_get_tabstrip_selected_text_color (&textcolor); } - } else { + } + else { clr = clr_mid; if (theming) { textcolor = style->text[GTK_STATE_NORMAL]; - } else { + } + else { gtkui_get_tabstrip_text_color (&textcolor); } } - float fg[3] = {(float)textcolor.red/0xffff, (float)textcolor.green/0xffff, (float)textcolor.blue/0xffff}; -#if !GTK_CHECK_VERSION(3,0,0) + float fg[3] = { (float)textcolor.red / 0xffff, + (float)textcolor.green / 0xffff, + (float)textcolor.blue / 0xffff }; +#if !GTK_CHECK_VERSION(3, 0, 0) gdk_gc_set_rgb_fg_color (gc, &clr); gdk_draw_rectangle (backbuf, gc, TRUE, tabarea_width, 1, add_playlist_btn_width, add_playlist_btn_height); draw_set_fg_color (&ts->drawctx, fg); - draw_text_custom (&ts->drawctx, tabarea_width, playlist_button_border, add_playlist_btn_width, 2, DDB_TABSTRIP_FONT, TRUE, FALSE, "+"); + draw_text_custom ( + &ts->drawctx, + tabarea_width, + playlist_button_border, + add_playlist_btn_width, + 2, + DDB_TABSTRIP_FONT, + TRUE, + FALSE, + "+"); #else - cairo_set_source_rgb (cr, clr.red/65535.f, clr.green/65535.f, clr.blue/65535.0); + cairo_set_source_rgb (cr, clr.red / 65535.f, clr.green / 65535.f, clr.blue / 65535.0); cairo_rectangle (cr, tabarea_width, 1, add_playlist_btn_width, add_playlist_btn_height); cairo_fill (cr); draw_set_fg_color (&ts->drawctx, fg); - draw_text_custom (&ts->drawctx, tabarea_width, playlist_button_border, add_playlist_btn_width, 2, DDB_TABSTRIP_FONT, TRUE, FALSE, "+"); + draw_text_custom ( + &ts->drawctx, + tabarea_width, + playlist_button_border, + add_playlist_btn_width, + 2, + DDB_TABSTRIP_FONT, + TRUE, + FALSE, + "+"); #endif } draw_end (&ts->drawctx); -#if !GTK_CHECK_VERSION(3,0,0) +#if !GTK_CHECK_VERSION(3, 0, 0) gdk_gc_unref (gc); #endif } @@ -970,7 +1118,7 @@ get_tab_under_cursor (DdbTabStrip *ts, int x) { GtkAllocation a; int buttons_width = add_playlist_btn_width + (need_arrows ? arrow_widget_width : 0); - gtk_widget_get_allocation (GTK_WIDGET(ts), &a); + gtk_widget_get_allocation (GTK_WIDGET (ts), &a); if (x > a.width - buttons_width) { return -1; } @@ -1019,7 +1167,7 @@ tabstrip_scroll_left (DdbTabStrip *ts) { static void tabstrip_scroll_right (DdbTabStrip *ts) { int tab = deadbeef->plt_get_curr_idx (); - if (tab < deadbeef->plt_get_count ()-1) { + if (tab < deadbeef->plt_get_count () - 1) { tab++; deadbeef->plt_set_curr_idx (tab); } @@ -1042,30 +1190,24 @@ tabstrip_scroll_cb (gpointer data) { } gboolean -on_tabstrip_scroll_event(GtkWidget *widget, - GdkEventScroll *event) -{ +on_tabstrip_scroll_event (GtkWidget *widget, GdkEventScroll *event) { DdbTabStrip *ts = DDB_TABSTRIP (widget); - if(event->direction == GDK_SCROLL_UP) - { - tabstrip_scroll_left(ts); + if (event->direction == GDK_SCROLL_UP) { + tabstrip_scroll_left (ts); } - else if (event->direction == GDK_SCROLL_DOWN) - { - tabstrip_scroll_right(ts); + else if (event->direction == GDK_SCROLL_DOWN) { + tabstrip_scroll_right (ts); } return TRUE; } gboolean -on_tabstrip_button_press_event(GtkWidget *widget, - GdkEventButton *event) -{ +on_tabstrip_button_press_event (GtkWidget *widget, GdkEventButton *event) { DdbTabStrip *ts = DDB_TABSTRIP (widget); tab_clicked = get_tab_under_cursor (ts, event->x); - if (TEST_LEFT_CLICK(event)) { + if (TEST_LEFT_CLICK (event)) { if (tab_clicked == deadbeef->plt_get_curr_idx ()) { gtk_widget_grab_focus (widget); } @@ -1081,7 +1223,9 @@ on_tabstrip_button_press_event(GtkWidget *widget, } return TRUE; } - else if (event->x >= a.width - (arrow_widget_width + add_playlist_btn_width) && event->x < a.width - add_playlist_btn_width) { + else if ( + event->x >= a.width - (arrow_widget_width + add_playlist_btn_width) && + event->x < a.width - add_playlist_btn_width) { if (event->type == GDK_BUTTON_PRESS) { tabstrip_scroll_right (ts); ts->scroll_direction = 1; @@ -1146,14 +1290,14 @@ on_tabstrip_button_press_event(GtkWidget *widget, ts->prev_x = event->x; tab_moved = 0; } - else if (TEST_RIGHT_CLICK(event)) { + else if (TEST_RIGHT_CLICK (event)) { ddb_playlist_t *plt = deadbeef->plt_get_for_idx (tab_clicked); GtkWidget *menu = gtkui_create_pltmenu (plt); if (plt != NULL) { deadbeef->plt_unref (plt); } gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (widget), NULL); - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time()); + gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time ()); } else if (event->button == 2) { if (tab_clicked == -1) { @@ -1166,9 +1310,9 @@ on_tabstrip_button_press_event(GtkWidget *widget, } else if (deadbeef->conf_get_int ("gtkui.mmb_delete_playlist", 1)) { if (tab_clicked != -1) { - ddb_playlist_t *plt = deadbeef->plt_get_for_idx(tab_clicked); + ddb_playlist_t *plt = deadbeef->plt_get_for_idx (tab_clicked); if (plt != NULL) { - gtkui_remove_playlist(plt); + gtkui_remove_playlist (plt); deadbeef->plt_unref (plt); } } @@ -1177,11 +1321,8 @@ on_tabstrip_button_press_event(GtkWidget *widget, return TRUE; } - gboolean -on_tabstrip_button_release_event (GtkWidget *widget, - GdkEventButton *event) -{ +on_tabstrip_button_release_event (GtkWidget *widget, GdkEventButton *event) { DdbTabStrip *ts = DDB_TABSTRIP (widget); if (event->button == 1) { if (ts->scroll_timer > 0) { @@ -1199,9 +1340,7 @@ on_tabstrip_button_release_event (GtkWidget *widget, } gboolean -on_tabstrip_configure_event (GtkWidget *widget, - GdkEventConfigure *event) -{ +on_tabstrip_configure_event (GtkWidget *widget, GdkEventConfigure *event) { DdbTabStrip *ts = DDB_TABSTRIP (widget); draw_init_font (&ts->drawctx, DDB_TABSTRIP_FONT, 1); tabstrip_adjust_hscroll (ts); @@ -1209,7 +1348,7 @@ on_tabstrip_configure_event (GtkWidget *widget, int height = ts->row_height + 4; ts->calculated_height = height; int w; - draw_get_text_extents(&ts->drawctx, ">", 1, &w, NULL); + draw_get_text_extents (&ts->drawctx, ">", 1, &w, NULL); ts->calculated_arrow_width = w; GtkAllocation a; gtk_widget_get_allocation (widget, &a); @@ -1220,8 +1359,7 @@ on_tabstrip_configure_event (GtkWidget *widget, } static void -tabstrip_update_font (DdbTabStrip *ts, GtkWidget *widget) -{ +tabstrip_update_font (DdbTabStrip *ts, GtkWidget *widget) { draw_init_font (&ts->drawctx, DDB_TABSTRIP_FONT, 1); tabstrip_adjust_hscroll (ts); int height = draw_get_listview_rowheight (&ts->drawctx) + 4; @@ -1234,8 +1372,7 @@ tabstrip_update_font (DdbTabStrip *ts, GtkWidget *widget) } gboolean -on_tabstrip_draw (GtkWidget *widget, cairo_t *cr) -{ +on_tabstrip_draw (GtkWidget *widget, cairo_t *cr) { DdbTabStrip *ts = DDB_TABSTRIP (widget); tabstrip_update_font (ts, widget); tabstrip_render (ts, cr); @@ -1243,9 +1380,7 @@ on_tabstrip_draw (GtkWidget *widget, cairo_t *cr) } gboolean -on_tabstrip_expose_event (GtkWidget *widget, - GdkEventExpose *event) -{ +on_tabstrip_expose_event (GtkWidget *widget, GdkEventExpose *event) { DdbTabStrip *ts = DDB_TABSTRIP (widget); tabstrip_update_font (ts, widget); @@ -1256,15 +1391,13 @@ on_tabstrip_expose_event (GtkWidget *widget, } gboolean -on_tabstrip_motion_notify_event (GtkWidget *widget, - GdkEventMotion *event) -{ +on_tabstrip_motion_notify_event (GtkWidget *widget, GdkEventMotion *event) { DdbTabStrip *ts = DDB_TABSTRIP (widget); int ev_x; GdkModifierType ev_state; ev_x = event->x; ev_state = event->state; -#if GTK_CHECK_VERSION(2,12,0) +#if GTK_CHECK_VERSION(2, 12, 0) gdk_event_request_motions (event); #endif if ((ev_state & GDK_BUTTON1_MASK) && ts->prepare) { @@ -1273,7 +1406,7 @@ on_tabstrip_motion_notify_event (GtkWidget *widget, } } if (!ts->prepare && ts->dragging >= 0) { -// gdk_window_set_cursor (gtk_widget_get_window(widget), cursor_drag); + // gdk_window_set_cursor (gtk_widget_get_window(widget), cursor_drag); ts->movepos = ev_x - ts->dragpt[0]; // find closest tab to the left @@ -1288,7 +1421,7 @@ on_tabstrip_motion_notify_event (GtkWidget *widget, int cnt = deadbeef->plt_get_count (); for (idx = 0; idx < cnt; idx++) { int width = ddb_tabstrip_get_tab_width (ts, idx); - if (idx != ts->dragging && x <= ts->movepos && x + width/2 - tab_overlap_size > ts->movepos) { + if (idx != ts->dragging && x <= ts->movepos && x + width / 2 - tab_overlap_size > ts->movepos) { inspos = idx; break; } @@ -1298,7 +1431,7 @@ on_tabstrip_motion_notify_event (GtkWidget *widget, deadbeef->plt_move (ts->dragging, inspos); tab_moved = 1; ts->dragging = inspos; - deadbeef->plt_set_curr_idx(ts->dragging); + deadbeef->plt_set_curr_idx (ts->dragging); deadbeef->sendmessage (DB_EV_PLAYLISTCHANGED, 0, DDB_PLAYLIST_CHANGE_POSITION, 0); } gtk_widget_queue_draw (widget); @@ -1325,7 +1458,7 @@ on_tabstrip_motion_notify_event (GtkWidget *widget, gtk_widget_set_has_tooltip (widget, FALSE); } GtkAllocation a; - gtk_widget_get_allocation(widget, &a); + gtk_widget_get_allocation (widget, &a); ts->add_playlistbtn_hover = (ev_x > a.width - add_playlist_btn_width) ? 1 : 0; gtk_widget_queue_draw (widget); } @@ -1335,9 +1468,9 @@ on_tabstrip_motion_notify_event (GtkWidget *widget, static gboolean _tabstrip_drag_pick (void *ctx) { GtkWidget *widget = ctx; - DdbTabStrip *ts = DDB_TABSTRIP(widget); + DdbTabStrip *ts = DDB_TABSTRIP (widget); gint x, y; - gtk_widget_get_pointer(widget, &x, &y); + gtk_widget_get_pointer (widget, &x, &y); int tab = get_tab_under_cursor (DDB_TABSTRIP (widget), x); int prev = deadbeef->plt_get_curr_idx (); if (tab != -1 && tab != prev) { @@ -1348,17 +1481,12 @@ _tabstrip_drag_pick (void *ctx) { } gboolean -on_tabstrip_drag_motion_event (GtkWidget *widget, - GdkDragContext *drag_context, - gint x, - gint y, - guint time) -{ - DdbTabStrip *ts = DDB_TABSTRIP(widget); +on_tabstrip_drag_motion_event (GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y, guint time) { + DdbTabStrip *ts = DDB_TABSTRIP (widget); if (ts->pick_drag_timer != 0) { - g_source_remove(ts->pick_drag_timer); + g_source_remove (ts->pick_drag_timer); } - ts->pick_drag_timer = g_timeout_add(500, _tabstrip_drag_pick, widget); + ts->pick_drag_timer = g_timeout_add (500, _tabstrip_drag_pick, widget); GList *targets = gdk_drag_context_list_targets (drag_context); int cnt = g_list_length (targets); @@ -1378,8 +1506,7 @@ on_tabstrip_drag_motion_event (GtkWidget *widget, else { GdkModifierType mask; - gdk_window_get_pointer (gtk_widget_get_window (widget), - NULL, NULL, &mask); + gdk_window_get_pointer (gtk_widget_get_window (widget), NULL, NULL, &mask); if (mask & GDK_CONTROL_MASK) { gdk_drag_status (drag_context, GDK_ACTION_COPY, time); } @@ -1395,36 +1522,32 @@ ddb_tabstrip_refresh (DdbTabStrip *ts) { } gboolean -on_tabstrip_key_press_event (GtkWidget *widget, - GdkEventKey *event) -{ +on_tabstrip_key_press_event (GtkWidget *widget, GdkEventKey *event) { switch (event->keyval) { case GDK_Left: - tabstrip_scroll_left(DDB_TABSTRIP(widget)); - return TRUE; + tabstrip_scroll_left (DDB_TABSTRIP (widget)); + break; case GDK_Right: - tabstrip_scroll_right(DDB_TABSTRIP(widget)); - return TRUE; - case GDK_F2: - { - int idx = deadbeef->plt_get_curr_idx (); - if (idx != -1) { - gtkui_rename_playlist_at_index(idx); - } - } + tabstrip_scroll_right (DDB_TABSTRIP (widget)); break; + case GDK_F2: { + int idx = deadbeef->plt_get_curr_idx (); + if (idx != -1) { + gtkui_rename_playlist_at_index (idx); + } + } break; + default: + return on_mainwin_key_press_event (widget, event, NULL); } - return FALSE; + return TRUE; } gboolean -on_tabstrip_leave_notify_event (GtkWidget *widget, GdkEventCrossing *event_crossing) -{ +on_tabstrip_leave_notify_event (GtkWidget *widget, GdkEventCrossing *event_crossing) { DdbTabStrip *ts = DDB_TABSTRIP (widget); ts->add_playlistbtn_hover = 0; - gtk_widget_queue_draw(widget); + gtk_widget_queue_draw (widget); return FALSE; } -