Commit 1ed60c98 authored by Sebastian Ramacher's avatar Sebastian Ramacher

Remove unused tabs support

Signed-off-by: Sebastian Ramacher's avatarSebastian Ramacher <sebastian+dev@ramacher.at>
parent a1632751
......@@ -58,22 +58,6 @@
background-color: @statusbar-bg@;
}
/* Tabbar */
#@session@ .tab {
color: @tabbar-fg@;
background-color: @tabbar-bg@;
}
#@session@ label.tab {
padding: 4px;
}
#@session@ .tab:selected {
color: @tabbar-focus-fg@;
background-color: @tabbar-focus-bg@;
}
/* Notification area */
#@session@ .notification {
......
......@@ -63,22 +63,6 @@
background-color: @statusbar-bg@;
}
/* Tabbar */
#@session@ .tab {
color: @tabbar-fg@;
background-color: @tabbar-bg@;
}
#@session@ GtkLabel.tab {
padding: 4px;
}
#@session@ .tab:selected {
color: @tabbar-focus-fg@;
background-color: @tabbar-focus-bg@;
}
/* Notification area */
#@session@ .notification {
......
......@@ -204,10 +204,6 @@ girara_config_load_default(girara_session_t* session)
girara_setting_add(session, "notification-bg", "#FFFFFF", STRING, TRUE, _("Notification background color"), NULL, NULL);
girara_setting_add(session, "scrollbar-fg", "#DDDDDD", STRING, TRUE, _("Scrollbar foreground color"), NULL, NULL);
girara_setting_add(session, "scrollbar-bg", "#000000", STRING, TRUE, _("Scrollbar background color"), NULL, NULL);
girara_setting_add(session, "tabbar-fg", "#939393", STRING, TRUE, _("Tab bar foreground color"), NULL, NULL);
girara_setting_add(session, "tabbar-bg", "#000000", STRING, TRUE, _("Tab bar background color"), NULL, NULL);
girara_setting_add(session, "tabbar-focus-fg", "#9FBC00", STRING, TRUE, _("Tab bar foreground color (active)"), NULL, NULL);
girara_setting_add(session, "tabbar-focus-bg", "#000000", STRING, TRUE, _("Tab bar background color (active)"), NULL, NULL);
girara_setting_add(session, "word-separator", " /.-=&#?", STRING, TRUE, NULL, NULL, NULL);
girara_setting_add(session, "window-width", &window_width, INT, TRUE, _("Initial window width"), NULL, NULL);
girara_setting_add(session, "window-height", &window_height, INT, TRUE, _("Initial window height"), NULL, NULL);
......@@ -228,9 +224,6 @@ girara_config_load_default(girara_session_t* session)
girara_shortcut_add(session, GDK_CONTROL_MASK, GDK_KEY_c, NULL, girara_sc_abort, normal_mode, 0, NULL);
girara_shortcut_add(session, GDK_CONTROL_MASK, GDK_KEY_q, NULL, girara_sc_quit, normal_mode, 0, NULL);
girara_shortcut_add(session, 0, GDK_KEY_colon, NULL, girara_sc_focus_inputbar, normal_mode, 0, ":");
girara_shortcut_add(session, GDK_CONTROL_MASK, GDK_KEY_w, NULL, girara_sc_tab_close, normal_mode, 0, NULL);
girara_shortcut_add(session, 0, 0, "gt", girara_sc_tab_navigate, normal_mode, GIRARA_NEXT, NULL);
girara_shortcut_add(session, 0, 0, "gT", girara_sc_tab_navigate, normal_mode, GIRARA_PREVIOUS, NULL);
/* inputbar shortcuts */
girara_inputbar_shortcut_add(session, GDK_CONTROL_MASK, GDK_KEY_j, girara_isc_activate, 0, NULL);
......@@ -279,8 +272,6 @@ girara_config_load_default(girara_session_t* session)
girara_shortcut_mapping_add(session, "focus_inputbar", girara_sc_focus_inputbar);
girara_shortcut_mapping_add(session, "quit", girara_sc_quit);
girara_shortcut_mapping_add(session, "set", girara_sc_set);
girara_shortcut_mapping_add(session, "tab_next", girara_sc_tab_navigate_next);
girara_shortcut_mapping_add(session, "tab_prev", girara_sc_tab_navigate_prev);
girara_shortcut_mapping_add(session, "toggle_inputbar", girara_sc_toggle_inputbar);
girara_shortcut_mapping_add(session, "toggle_statusbar", girara_sc_toggle_statusbar);
}
......
......@@ -65,10 +65,6 @@ init_template_engine(GiraraTemplate* csstemplate)
"notification-bg",
"scrollbar-fg",
"scrollbar-bg",
"tabbar-fg",
"tabbar-bg",
"tabbar-focus-fg",
"tabbar-focus-bg",
"bottombox-padding1",
"bottombox-padding2",
"bottombox-padding3",
......@@ -192,11 +188,7 @@ fill_template_with_values(girara_session_t* session)
"notification-fg",
"notification-bg",
"scrollbar-fg",
"scrollbar-bg",
"tabbar-fg",
"tabbar-bg",
"tabbar-focus-fg",
"tabbar-focus-bg",
"scrollbar-bg"
};
for (size_t i = 0; i < LENGTH(color_settings); ++i) {
......@@ -366,9 +358,7 @@ girara_session_create()
session->private_data->gtk.overlay = gtk_overlay_new();
session->private_data->gtk.bottom_box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 0));
session->gtk.statusbar_entries = GTK_BOX(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0));
session->gtk.tabbar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
session->gtk.inputbar_box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0));
gtk_box_set_homogeneous(GTK_BOX(session->gtk.tabbar), TRUE);
gtk_box_set_homogeneous(session->gtk.inputbar_box, TRUE);
session->gtk.view = gtk_scrolled_window_new(NULL, NULL);
session->gtk.viewport = gtk_viewport_new(NULL, NULL);
......@@ -522,7 +512,6 @@ girara_session_init(girara_session_t* session, const char* sessionname)
/* packing */
gtk_box_set_spacing(session->gtk.box, 0);
gtk_box_pack_start(session->gtk.box, GTK_WIDGET(session->gtk.tabbar), FALSE, FALSE, 0);
gtk_box_pack_start(session->gtk.box, GTK_WIDGET(session->gtk.view), TRUE, TRUE, 0);
/* box */
......
......@@ -29,12 +29,10 @@ struct girara_session_s
GtkBox *statusbar_entries; /**< Statusbar entry box */
GtkWidget *notification_area; /**< The notification area */
GtkWidget *notification_text; /**< The notification entry */
GtkWidget *tabbar; /**< The tabbar */
GtkBox *inputbar_box; /**< Inputbar box */
GtkWidget *inputbar; /**< Inputbar event box */
GtkLabel *inputbar_dialog; /**< Inputbar dialog */
GtkEntry *inputbar_entry; /**< Inputbar entry */
GtkNotebook *tabs; /**< The tabs notebook */
GtkBox *results; /**< Completion results */
Window embed; /**< Embedded window */
} gtk;
......
......@@ -7,7 +7,6 @@
#include "internal.h"
#include "session.h"
#include "settings.h"
#include "tabs.h"
#include <gtk/gtk.h>
#include <string.h>
......@@ -352,67 +351,6 @@ girara_sc_quit(girara_session_t* session, girara_argument_t* UNUSED(argument), g
return false;
}
bool
girara_sc_tab_close(girara_session_t* session, girara_argument_t* UNUSED(argument), girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{
g_return_val_if_fail(session != NULL, false);
girara_tab_t* tab = girara_tab_current_get(session);
if (tab != NULL) {
girara_tab_remove(session, tab);
}
return false;
}
bool
girara_sc_tab_navigate(girara_session_t* session, girara_argument_t* argument, girara_event_t* UNUSED(event), unsigned int t)
{
g_return_val_if_fail(session != NULL, false);
const unsigned int number_of_tabs = girara_get_number_of_tabs(session);
if (number_of_tabs == 0) {
return false;
}
unsigned int current_tab = girara_tab_position_get(session, girara_tab_current_get(session));
unsigned int step = (argument->n == GIRARA_PREVIOUS) ? -1 : 1;
unsigned int new_tab = (current_tab + step) % number_of_tabs;
if (t != 0 && t <= number_of_tabs) {
new_tab = t - 1;
}
girara_tab_t* tab = girara_tab_get(session, new_tab);
if (tab != NULL) {
girara_tab_current_set(session, tab);
}
girara_tab_update(session);
return false;
}
bool
girara_sc_tab_navigate_next(girara_session_t* session,
girara_argument_t* argument,
girara_event_t* event, unsigned int t)
{
argument->n = GIRARA_NEXT;
return girara_sc_tab_navigate(session, argument, event, t);
}
bool
girara_sc_tab_navigate_prev(girara_session_t* session,
girara_argument_t* argument,
girara_event_t* event, unsigned int t)
{
argument->n = GIRARA_PREVIOUS;
return girara_sc_tab_navigate(session, argument, event, t);
}
static void
girara_toggle_widget_visibility(GtkWidget* widget)
{
......@@ -447,16 +385,6 @@ girara_sc_toggle_statusbar(girara_session_t* session, girara_argument_t* UNUSED(
return true;
}
bool
girara_sc_toggle_tabbar(girara_session_t* session, girara_argument_t* UNUSED(argument), girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{
g_return_val_if_fail(session != NULL, false);
girara_toggle_widget_visibility(GTK_WIDGET(session->gtk.tabbar));
return true;
}
static girara_list_t*
argument_to_argument_list(girara_argument_t* argument) {
girara_list_t* argument_list = girara_list_new();
......
......@@ -107,58 +107,6 @@ bool girara_sc_abort(girara_session_t* session, girara_argument_t* argument,
bool girara_sc_quit(girara_session_t* session, girara_argument_t* argument,
girara_event_t* event, unsigned int t);
/**
* Closes the current tab
*
* @param session The used girara session
* @param argument The argument
* @param event Girara event
* @param t Number of executions
* @return true No error occurred
* @return false An error occurred (abort execution)
*/
bool girara_sc_tab_close(girara_session_t* session, girara_argument_t* argument,
girara_event_t* event, unsigned int t);
/**
* Default shortcut function to navigate through tabs
*
* @param session The used girara session
* @param argument The argument
* @param event Girara event
* @param t Number of execution
* @return true No error occurred
* @return false An error occurred (abort execution)
*/
bool girara_sc_tab_navigate(girara_session_t* session, girara_argument_t*
argument, girara_event_t* event, unsigned int t);
/**
* Navigate to the next tab
*
* @param session The used girara session
* @param argument The used argument
* @param event Girara event
* @param t Number of executions
* @return true if no error occurred otherwise false
*/
bool girara_sc_tab_navigate_next(girara_session_t* session,
girara_argument_t* argument,
girara_event_t* event, unsigned int t);
/**
* Navigate to the previous tab
*
* @param session The used girara session
* @param argument The used argument
* @param event Girara event
* @param t Number of executions
* @return true if no error occurred otherwise false
*/
bool girara_sc_tab_navigate_prev(girara_session_t* session,
girara_argument_t* argument,
girara_event_t* event, unsigned int t);
/**
* Toggles the visibility of the inputbar
*
......@@ -185,19 +133,6 @@ bool girara_sc_toggle_inputbar(girara_session_t* session, girara_argument_t*
bool girara_sc_toggle_statusbar(girara_session_t* session, girara_argument_t*
argument, girara_event_t* event, unsigned int t);
/**
* Toggles the visibility of the tabbar
*
* @param session The used girara session
* @param argument The argument
* @param event Girara event
* @param t Number of execution
* @return true No error occurred
* @return false An error occurred (abort execution)
*/
bool girara_sc_toggle_tabbar(girara_session_t* session, girara_argument_t*
argument, girara_event_t* event, unsigned int t);
/**
* Passes the argument to the set command
*
......
/* See LICENSE file for license and copyright information */
#include "tabs.h"
#include "session.h"
#include "internal.h"
#define UNTITLED_TAB_TITLE "untitled"
/**
* Default implementation of the event that is executed if a tab is clicked
*
* @param widget The widget
* @param event The event
* @param data Additional data
* @return true if an error occurred, otherwise false
*/
static gboolean girara_callback_tab_clicked(GtkWidget* widget, GdkEventButton* event, gpointer data);
void
girara_tabs_enable(girara_session_t* session)
{
if (session == NULL || session->gtk.tabs != NULL) {
return;
}
session->gtk.tabs = GTK_NOTEBOOK(gtk_notebook_new());
gtk_notebook_set_show_border(session->gtk.tabs, FALSE);
gtk_notebook_set_show_tabs(session->gtk.tabs, FALSE);
/* Display tab view */
girara_set_view(session, GTK_WIDGET(session->gtk.tabs));
/* Display tab bar */
if (session->gtk.tabbar) {
gtk_widget_show(session->gtk.tabbar);
}
}
girara_tab_t*
girara_tab_new(girara_session_t* session, const char* title, GtkWidget* widget,
bool next_to_current, void* data)
{
if (session == NULL || widget == NULL) {
return NULL;
}
girara_tab_t* tab = g_slice_new(girara_tab_t);
tab->title = title ? g_strdup(title) : g_strdup(UNTITLED_TAB_TITLE);
tab->widget = widget;
tab->session = session;
tab->data = data;
int position = (next_to_current) ?
(gtk_notebook_get_current_page(session->gtk.tabs) + 1) : -1;
/* insert tab into notebook */
if (gtk_notebook_insert_page(session->gtk.tabs, tab->widget, NULL, position) == -1) {
g_free(tab->title);
g_slice_free(girara_tab_t, tab);
return NULL;
}
/* create tab label */
GtkWidget *tab_label = gtk_label_new(tab->title);
GtkWidget *tab_event = gtk_event_box_new();
g_object_set_data(G_OBJECT(tab->widget), "event", (gpointer) tab_event);
g_object_set_data(G_OBJECT(tab->widget), "label", (gpointer) tab_label);
g_object_set_data(G_OBJECT(tab->widget), "tab", (gpointer) tab);
g_signal_connect(G_OBJECT(tab_event), "button_press_event",
G_CALLBACK(girara_callback_tab_clicked), tab);
gtk_widget_set_halign(tab_label, GTK_ALIGN_START);
gtk_widget_set_valign(tab_label, GTK_ALIGN_START);
widget_add_class(tab_label, "tab");
widget_add_class(tab_event, "tab");
gtk_label_set_ellipsize(GTK_LABEL(tab_label), PANGO_ELLIPSIZE_MIDDLE);
gtk_container_add(GTK_CONTAINER(tab_event), tab_label);
gtk_box_pack_start(GTK_BOX(session->gtk.tabbar), tab_event, TRUE, TRUE, 0);
gtk_box_reorder_child(GTK_BOX(session->gtk.tabbar), tab_event, position);
gtk_widget_show_all(widget);
gtk_widget_show_all(tab_event);
gtk_notebook_set_current_page(session->gtk.tabs, position);
girara_tab_update(session);
return tab;
}
void
girara_tab_remove(girara_session_t* session, girara_tab_t* tab)
{
if (session == NULL || tab == NULL || session->gtk.tabbar == NULL) {
return;
}
/* Remove page from notebook */
int tab_id = girara_tab_position_get(session, tab);
/* Remove entry from tabbar */
GtkWidget* tab_event = GTK_WIDGET(g_object_get_data(G_OBJECT(tab->widget), "event"));
if (tab_event != NULL) {
gtk_container_remove(GTK_CONTAINER(session->gtk.tabbar), tab_event);
}
if (tab_id != -1) {
gtk_notebook_remove_page(session->gtk.tabs, tab_id);
}
g_free(tab->title);
g_slice_free(girara_tab_t, tab);
girara_tab_update(session);
}
girara_tab_t*
girara_tab_get(girara_session_t* session, unsigned int index)
{
if (session == NULL || session->gtk.tabs == NULL) {
return 0;
}
GtkWidget* widget = gtk_notebook_get_nth_page(session->gtk.tabs, index);
return (girara_tab_t*) g_object_get_data(G_OBJECT(widget), "tab");
}
int
girara_get_number_of_tabs(girara_session_t* session)
{
if (session == NULL || session->gtk.tabs == NULL) {
return 0;
}
return gtk_notebook_get_n_pages(session->gtk.tabs);
}
void
girara_tab_update(girara_session_t* session)
{
if (session == NULL || session->gtk.tabs == NULL) {
return;
}
int number_of_tabs = girara_get_number_of_tabs(session);
int current_tab = girara_tab_position_get(session, girara_tab_current_get(session));
for (int i = 0; i < number_of_tabs; i++) {
GtkWidget* widget = gtk_notebook_get_nth_page(session->gtk.tabs, i);
girara_tab_t* tab = (girara_tab_t*) g_object_get_data(G_OBJECT(widget), "tab");
if (tab == NULL) {
continue;
}
GtkWidget* tab_event = GTK_WIDGET(g_object_get_data(G_OBJECT(tab->widget), "event"));
GtkWidget* tab_label = GTK_WIDGET(g_object_get_data(G_OBJECT(tab->widget), "label"));
if (i == current_tab) {
gtk_widget_set_state_flags(tab_event, GTK_STATE_FLAG_SELECTED, false);
gtk_widget_set_state_flags(tab_label, GTK_STATE_FLAG_SELECTED, false);
} else {
gtk_widget_unset_state_flags(tab_event, GTK_STATE_FLAG_SELECTED);
gtk_widget_unset_state_flags(tab_label, GTK_STATE_FLAG_SELECTED);
}
}
}
girara_tab_t*
girara_tab_current_get(girara_session_t* session)
{
if (session == NULL || session->gtk.tabs == NULL) {
return NULL;
}
int current = gtk_notebook_get_current_page(session->gtk.tabs);
if (current != -1) {
GtkWidget* widget = gtk_notebook_get_nth_page(session->gtk.tabs, current);
return (girara_tab_t*) g_object_get_data(G_OBJECT(widget), "tab");
} else {
return NULL;
}
}
void
girara_tab_current_set(girara_session_t* session, girara_tab_t* tab)
{
if (session == NULL || session->gtk.tabs == NULL
|| tab == NULL || tab->widget == NULL) {
return;
}
int index = gtk_notebook_page_num(session->gtk.tabs, tab->widget);
if (index != -1) {
gtk_notebook_set_current_page(session->gtk.tabs, index);
}
girara_tab_update(session);
}
void
girara_tab_title_set(girara_tab_t* tab, const char* title)
{
if (tab == NULL) {
return;
}
g_free(tab->title);
tab->title = title ? g_strdup(title) : g_strdup(UNTITLED_TAB_TITLE);
GtkWidget* tab_label = GTK_WIDGET(g_object_get_data(G_OBJECT(tab->widget), "label"));
if (tab_label) {
gtk_label_set_text(GTK_LABEL(tab_label), tab->title);
}
}
const char*
girara_tab_title_get(girara_tab_t* tab)
{
if (tab == NULL) {
return NULL;
}
return tab->title;
}
int
girara_tab_position_get(girara_session_t* session, girara_tab_t* tab)
{
if (session == NULL || session->gtk.tabs == NULL
|| tab == NULL || tab->widget == NULL) {
return -1;
}
return gtk_notebook_page_num(session->gtk.tabs, tab->widget);
}
void
girara_tab_position_set(girara_session_t* session, girara_tab_t* tab, unsigned int position)
{
if (session == NULL || session->gtk.tabs == NULL
|| tab == NULL || tab->widget == NULL) {
return;
}
gtk_notebook_reorder_child(session->gtk.tabs, tab->widget, position);
}
static gboolean
girara_callback_tab_clicked(GtkWidget* UNUSED(widget), GdkEventButton* event, gpointer data)
{
if (data == NULL) {
return false;
}
girara_tab_t* tab = (girara_tab_t*) data;
girara_session_t* session = tab->session;
switch (event->button) {
case 1:
girara_tab_current_set(session, tab);
break;
case 2:
girara_tab_remove(session, tab);
break;
}
return true;
}
/* See LICENSE file for license and copyright information */
#ifndef GIRARA_TABS_H
#define GIRARA_TABS_H
#include "types.h"
#include <gtk/gtk.h>
/**
* Structure of a tab
*/
struct girara_tab_s
{
char* title; /**< The title of the tab */
GtkWidget* widget; /**< The displayed widget of the tab */
void* data; /**< Custom data */
girara_session_t* session; /**< Girara session */
};
/**
* Enables the tab view. If girara_set_view is used, the tab bar will
* automatically vanish and girara_tabs_enable has to be called another time to
* re-enable it again.
*
* @param session The girara session
*/
void girara_tabs_enable(girara_session_t* session);
/**
* Creates and adds a new tab to the tab view
*
* @param session The girara session
* @param title Title of the tab (optional)
* @param widget Displayed widget
* @param next_to_current Tab should be created right next to the current one
* @param data Custom data
* @return A new tab object or NULL if an error occurred
*/
girara_tab_t* girara_tab_new(girara_session_t* session, const char* title,
GtkWidget* widget, bool next_to_current, void* data);
/**
* Removes and destroys a tab from the tab view
*
* @param session The girara session
* @param tab Tab
*/
void girara_tab_remove(girara_session_t* session, girara_tab_t* tab);
/**
* Returns the tab at the given index
*
* @param session The girara session
* @param index Index of the tab
* @return The tab object or NULL if an error occurred
*/
girara_tab_t* girara_tab_get(girara_session_t* session, unsigned int index);
/**
* Returns the number of tabs
*
* @param session The girara session
* @return The number of tabs
*/
int girara_get_number_of_tabs(girara_session_t* session);
/**
* Updates the color and states of all tabs
*
* @param session The girara session
*/
void girara_tab_update(girara_session_t* session);
/**
* Returns the current tab
*
* @param session The girara session
* @return The current tab or NULL if an error occurred
*/
girara_tab_t* girara_tab_current_get(girara_session_t* session);
/**
* Sets the current tab
*
* @param session The girara session
* @param tab The new current tab
*/
void girara_tab_current_set(girara_session_t* session, girara_tab_t* tab);
/**
* Sets the shown title of the tab
*
* @param tab The tab
* @param title The new title
*/
void girara_tab_title_set(girara_tab_t* tab, const char* title);
/**
* Returns the title of the tab
*
* @param tab The tab
* @return The title of the tab or NULL if an error occurred
*/
const char* girara_tab_title_get(girara_tab_t* tab);
/**
* Returns the position of the tab
*
* @param session Girara session
* @param tab The tab
* @return The id of the tab or -1 if an error occurred
*/
int girara_tab_position_get(girara_session_t* session, girara_tab_t* tab);
/**
* Sets the new position of the tab
*
* @param session Girara session
* @param tab The tab
* @param position The new position
*/
void girara_tab_position_set(girara_session_t* session, girara_tab_t* tab,
unsigned int position);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment