diff options
author | P. J. McDermott <pj@pehjota.net> | 2018-10-03 23:56:57 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2018-10-03 23:56:57 (EDT) |
commit | 5ea974b38f712d39a899f83247236e3e33c17091 (patch) | |
tree | f69cf04ee46abdc4044b2b5ee760573dd7b74192 | |
parent | 1d99bb8165bc0dfac45a2fb74e18c5b9c608a5c7 (diff) | |
download | marquee-5ea974b38f712d39a899f83247236e3e33c17091.zip marquee-5ea974b38f712d39a899f83247236e3e33c17091.tar.gz marquee-5ea974b38f712d39a899f83247236e3e33c17091.tar.bz2 |
MqTabLabel: Move image/title functions up
-rw-r--r-- | src/tab-label.c | 306 |
1 files changed, 153 insertions, 153 deletions
diff --git a/src/tab-label.c b/src/tab-label.c index ca6b0e0..9d91d6c 100644 --- a/src/tab-label.c +++ b/src/tab-label.c @@ -64,117 +64,6 @@ struct _MqTabLabelClass { G_DEFINE_TYPE(MqTabLabel, mq_tab_label, GTK_TYPE_EVENT_BOX) static void -reload_tab_clicked_cb(GtkWidget G_GNUC_UNUSED *button, MqTabLabel *tab_label) -{ - webkit_web_view_reload(tab_label->web_view); - gtk_widget_hide(tab_label->popover); -} - -static void -duplicate_clicked_cb(GtkWidget G_GNUC_UNUSED *button, - G_GNUC_UNUSED MqTabLabel *tab_label) -{ - /* TODO */ -} - -static void -move_to_win_clicked_cb(GtkWidget G_GNUC_UNUSED *button, - G_GNUC_UNUSED MqTabLabel *tab_label) -{ - /* TODO */ -} - -static void -close_clicked_cb(GtkWidget G_GNUC_UNUSED *button, MqTabLabel *tab_label) -{ - /* This callback handles both the close button on the tab label and the - * one on the popover. Closing the tab automatically hides the popover, - * so don't bother conditionally hiding it if it's shown. */ - - mq_tab_page_close(tab_label->tab_page); -} - -static void -new_tab_clicked_cb(GtkWidget G_GNUC_UNUSED *button, MqTabLabel *tab_label) -{ - mq_notebook_insert_sibling( - MQ_NOTEBOOK(gtk_widget_get_parent(GTK_WIDGET(tab_label))), - NULL, - tab_label->tab_page, - TRUE); - gtk_widget_hide(tab_label->popover); -} - -static void -new_window_clicked_cb(GtkWidget G_GNUC_UNUSED *button, MqTabLabel *tab_label) -{ - mq_application_add_window( - mq_tab_page_get_application(tab_label->tab_page), NULL); - gtk_widget_hide(tab_label->popover); -} - -static void -undo_close_clicked_cb(GtkWidget G_GNUC_UNUSED *button, - G_GNUC_UNUSED MqTabLabel *tab_label) -{ - /* TODO */ -} - -#define BUTTON_ROWS 2 -#define BUTTON_COLS 4 -#define BTN(Y, X) buttons[Y * BUTTON_COLS + X] -#define NEW_BTN(Y, X, ID, ICON, TOOLTIP) \ - G_STMT_START { \ - BTN(Y, X) = gtk_button_new_from_icon_name(ICON, \ - GTK_ICON_SIZE_BUTTON); \ - gtk_widget_set_tooltip_text(BTN(Y, X), TOOLTIP); \ - gtk_widget_set_can_focus(BTN(Y, X), FALSE); \ - g_signal_connect(BTN(Y, X), "clicked", \ - G_CALLBACK(ID ## _clicked_cb), tab_label); \ - gtk_grid_attach(GTK_GRID(button_grid), BTN(Y, X), X, Y, 1, 1); \ - } G_STMT_END - -static void -create_tab_popover(GtkWidget *widget, MqTabLabel *tab_label) -{ - GtkWidget *button_grid; - GtkWidget *buttons[BUTTON_ROWS * BUTTON_COLS]; - - /* Set up button grid. */ - button_grid = gtk_grid_new(); - gtk_widget_set_halign(button_grid, GTK_ALIGN_CENTER); - - /* Set up buttons. */ - /* Y,X,ID, ICON, TOOLTIP */ - NEW_BTN(0,0,reload_tab, "view-refresh", _("Reload tab")); - NEW_BTN(0,1,duplicate, "edit-copy", _("Duplicate tab")); - NEW_BTN(0,2,move_to_win,"window-new", _("Move tab to new window")); - NEW_BTN(0,3,close, "window-close", _("Close tab")); - NEW_BTN(1,0,new_tab, "tab-new-symbolic",_("New tab")); - NEW_BTN(1,1,new_window, "window-new", _("New window")); - NEW_BTN(1,2,undo_close, "edit-undo", _("Undo close tab")); - - /* TODO: Duplicate tab */ - gtk_widget_set_sensitive(BTN(0, 1), FALSE); - /* TODO: Move tab to new window */ - gtk_widget_set_sensitive(BTN(0, 2), FALSE); - /* TODO: Undo close tab */ - gtk_widget_set_sensitive(BTN(1, 2), FALSE); - - /* Set up the popover. */ - tab_label->popover = gtk_popover_new(widget); - gtk_container_add(GTK_CONTAINER(tab_label->popover), button_grid); - - /* NB: gtk_popover_popup() is new in GTK+ 3.22. */ - gtk_widget_show_all(tab_label->popover); -} - -#undef BUTTON_ROWS -#undef BUTTON_COLS -#undef BTN -#undef NEW_BTN - -static void set_image(MqTabLabel *tab_label, GdkPixbuf *favicon) { if (favicon) { @@ -249,48 +138,6 @@ set_custom_title(MqTabLabel *tab_label, const gchar *title) } } -static void -favicon_cb(WebKitWebView G_GNUC_UNUSED *web_view, - GParamSpec G_GNUC_UNUSED *param_spec, MqTabLabel *tab_label) -{ - cairo_surface_t *surface; - GdkPixbuf *pixbuf; - GdkPixbuf *scaled_pixbuf; - - surface = webkit_web_view_get_favicon(tab_label->web_view); - scaled_pixbuf = NULL; - if (surface) { - pixbuf = gdk_pixbuf_get_from_surface(surface, 0, 0, - cairo_image_surface_get_width(surface), - cairo_image_surface_get_height(surface)); - if (pixbuf) { - scaled_pixbuf = gdk_pixbuf_scale_simple(pixbuf, 16, 16, - GDK_INTERP_BILINEAR); - g_object_unref(pixbuf); - } - } - - set_image(tab_label, scaled_pixbuf); -} - -static void -title_cb(WebKitWebView G_GNUC_UNUSED *web_view, - GParamSpec G_GNUC_UNUSED *param_spec, MqTabLabel *tab_label) -{ - set_title(tab_label, webkit_web_view_get_title(tab_label->web_view)); -} - -static void -set_web_view(MqTabLabel *tab_label, MqWebView *web_view) -{ - tab_label->web_view = WEBKIT_WEB_VIEW(web_view); - - g_signal_connect(web_view, "notify::favicon", - G_CALLBACK(favicon_cb), tab_label); - g_signal_connect(web_view, "notify::title", - G_CALLBACK(title_cb), tab_label); -} - static gboolean name_entry_key_press_event_cb(GtkEntry G_GNUC_UNUSED *entry, GdkEventKey *event, MqTabLabel *tab_label) @@ -393,6 +240,159 @@ create_name_popover(MqTabLabel *tab_label) gtk_widget_show_all(tab_label->name_popover); } +static void +reload_tab_clicked_cb(GtkWidget G_GNUC_UNUSED *button, MqTabLabel *tab_label) +{ + webkit_web_view_reload(tab_label->web_view); + gtk_widget_hide(tab_label->popover); +} + +static void +duplicate_clicked_cb(GtkWidget G_GNUC_UNUSED *button, + G_GNUC_UNUSED MqTabLabel *tab_label) +{ + /* TODO */ +} + +static void +move_to_win_clicked_cb(GtkWidget G_GNUC_UNUSED *button, + G_GNUC_UNUSED MqTabLabel *tab_label) +{ + /* TODO */ +} + +static void +close_clicked_cb(GtkWidget G_GNUC_UNUSED *button, MqTabLabel *tab_label) +{ + /* This callback handles both the close button on the tab label and the + * one on the popover. Closing the tab automatically hides the popover, + * so don't bother conditionally hiding it if it's shown. */ + + mq_tab_page_close(tab_label->tab_page); +} + +static void +new_tab_clicked_cb(GtkWidget G_GNUC_UNUSED *button, MqTabLabel *tab_label) +{ + mq_notebook_insert_sibling( + MQ_NOTEBOOK(gtk_widget_get_parent(GTK_WIDGET(tab_label))), + NULL, + tab_label->tab_page, + TRUE); + gtk_widget_hide(tab_label->popover); +} + +static void +new_window_clicked_cb(GtkWidget G_GNUC_UNUSED *button, MqTabLabel *tab_label) +{ + mq_application_add_window( + mq_tab_page_get_application(tab_label->tab_page), NULL); + gtk_widget_hide(tab_label->popover); +} + +static void +undo_close_clicked_cb(GtkWidget G_GNUC_UNUSED *button, + G_GNUC_UNUSED MqTabLabel *tab_label) +{ + /* TODO */ +} + +#define BUTTON_ROWS 2 +#define BUTTON_COLS 4 +#define BTN(Y, X) buttons[Y * BUTTON_COLS + X] +#define NEW_BTN(Y, X, ID, ICON, TOOLTIP) \ + G_STMT_START { \ + BTN(Y, X) = gtk_button_new_from_icon_name(ICON, \ + GTK_ICON_SIZE_BUTTON); \ + gtk_widget_set_tooltip_text(BTN(Y, X), TOOLTIP); \ + gtk_widget_set_can_focus(BTN(Y, X), FALSE); \ + g_signal_connect(BTN(Y, X), "clicked", \ + G_CALLBACK(ID ## _clicked_cb), tab_label); \ + gtk_grid_attach(GTK_GRID(button_grid), BTN(Y, X), X, Y, 1, 1); \ + } G_STMT_END + +static void +create_tab_popover(GtkWidget *widget, MqTabLabel *tab_label) +{ + GtkWidget *button_grid; + GtkWidget *buttons[BUTTON_ROWS * BUTTON_COLS]; + + /* Set up button grid. */ + button_grid = gtk_grid_new(); + gtk_widget_set_halign(button_grid, GTK_ALIGN_CENTER); + + /* Set up buttons. */ + /* Y,X,ID, ICON, TOOLTIP */ + NEW_BTN(0,0,reload_tab, "view-refresh", _("Reload tab")); + NEW_BTN(0,1,duplicate, "edit-copy", _("Duplicate tab")); + NEW_BTN(0,2,move_to_win,"window-new", _("Move tab to new window")); + NEW_BTN(0,3,close, "window-close", _("Close tab")); + NEW_BTN(1,0,new_tab, "tab-new-symbolic",_("New tab")); + NEW_BTN(1,1,new_window, "window-new", _("New window")); + NEW_BTN(1,2,undo_close, "edit-undo", _("Undo close tab")); + + /* TODO: Duplicate tab */ + gtk_widget_set_sensitive(BTN(0, 1), FALSE); + /* TODO: Move tab to new window */ + gtk_widget_set_sensitive(BTN(0, 2), FALSE); + /* TODO: Undo close tab */ + gtk_widget_set_sensitive(BTN(1, 2), FALSE); + + /* Set up the popover. */ + tab_label->popover = gtk_popover_new(widget); + gtk_container_add(GTK_CONTAINER(tab_label->popover), button_grid); + + /* NB: gtk_popover_popup() is new in GTK+ 3.22. */ + gtk_widget_show_all(tab_label->popover); +} + +#undef BUTTON_ROWS +#undef BUTTON_COLS +#undef BTN +#undef NEW_BTN + +static void +favicon_cb(WebKitWebView G_GNUC_UNUSED *web_view, + GParamSpec G_GNUC_UNUSED *param_spec, MqTabLabel *tab_label) +{ + cairo_surface_t *surface; + GdkPixbuf *pixbuf; + GdkPixbuf *scaled_pixbuf; + + surface = webkit_web_view_get_favicon(tab_label->web_view); + scaled_pixbuf = NULL; + if (surface) { + pixbuf = gdk_pixbuf_get_from_surface(surface, 0, 0, + cairo_image_surface_get_width(surface), + cairo_image_surface_get_height(surface)); + if (pixbuf) { + scaled_pixbuf = gdk_pixbuf_scale_simple(pixbuf, 16, 16, + GDK_INTERP_BILINEAR); + g_object_unref(pixbuf); + } + } + + set_image(tab_label, scaled_pixbuf); +} + +static void +title_cb(WebKitWebView G_GNUC_UNUSED *web_view, + GParamSpec G_GNUC_UNUSED *param_spec, MqTabLabel *tab_label) +{ + set_title(tab_label, webkit_web_view_get_title(tab_label->web_view)); +} + +static void +set_web_view(MqTabLabel *tab_label, MqWebView *web_view) +{ + tab_label->web_view = WEBKIT_WEB_VIEW(web_view); + + g_signal_connect(web_view, "notify::favicon", + G_CALLBACK(favicon_cb), tab_label); + g_signal_connect(web_view, "notify::title", + G_CALLBACK(title_cb), tab_label); +} + static gboolean button_press_cb(GtkWidget *widget, GdkEventButton *event, MqTabLabel *tab_label) |