Ejemplo n.º 1
0
static void i3_add_workspaces(i3WorkspacesPlugin *i3_workspaces)
{
    i3workspace **workspaces = i3wm_get_workspaces(i3_workspaces->i3wm);
    gint i;
    for (i = 1; i < I3_WORKSPACE_N; i++)
    {
        i3workspace *workspace = workspaces[i];
        if (workspace)
        {
            GtkWidget * button;
            button = gtk_button_new_with_label(workspace->name);

            /* if focused, bold the text on the button; otherwise use regular boldness */
            if (workspace->focused)
            {
                i3_focused_button (button, workspace->name);
            }
            else
            {
                i3_blurred_button (button, workspace->name);
            }

            g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(i3_on_workspace_clicked), i3_workspaces);

            gtk_button_set_use_underline(GTK_BUTTON(button), FALSE); /* avoid acceleration key interference */
            gtk_box_pack_start(GTK_BOX(i3_workspaces->hvbox), button, FALSE, FALSE, 0);
            gtk_widget_show(button);
            i3_workspaces->buttons[workspace->num] = button;
        }
    }
}
/**
 * add_workspaces:
 * @i3_workspaces: the workspaces plugin
 *
 * Add the workspaces.
 */
static void
add_workspaces(i3WorkspacesPlugin *i3_workspaces)
{
    GSList *wlist = i3wm_get_workspaces(i3_workspaces->i3wm);

    GSList *witem;
    for (witem = wlist; witem != NULL; witem = witem->next)
    {
        i3workspace *workspace = (i3workspace *) witem->data;
        if (workspace)
        {
            GtkWidget * button;
            button = xfce_panel_create_button();
            gtk_button_set_label(GTK_BUTTON(button), workspace->name);

            set_button_label(button, workspace, i3_workspaces->config);

            g_signal_connect(G_OBJECT(button), "clicked",
                    G_CALLBACK(on_workspace_clicked), i3_workspaces);

            /* avoid acceleration key interference */
            gtk_button_set_use_underline(GTK_BUTTON(button), FALSE);
            gtk_box_pack_end(GTK_BOX(i3_workspaces->hvbox), button, FALSE, FALSE, 0);
            gtk_widget_show(button);

            g_hash_table_insert(i3_workspaces->workspace_buttons, workspace, button);
        }
    }
}
/**
 * on_workspace_clicked:
 * @button: the clicked button
 * @data: the workspace plugin
 *
 * Workspace button click event handler.
 */
static void
on_workspace_clicked(GtkWidget *button, gpointer data)
{
    i3WorkspacesPlugin *i3_workspaces = (i3WorkspacesPlugin *)data;
    GSList *wlist = i3wm_get_workspaces(i3_workspaces->i3wm);
    i3workspace *workspace = NULL;

    GSList *witem;
    for (witem = wlist; witem != NULL; witem = witem->next)
    {
        workspace = (i3workspace *) witem->data;
        GtkWidget *w = (GtkWidget *) g_hash_table_lookup(i3_workspaces->workspace_buttons, workspace);

        if (w == button)
            break;
    }

    GError *err = NULL;
    i3wm_goto_workspace(i3_workspaces->i3wm, workspace, &err);
    if (err != NULL)
    {
        fprintf(stderr, "%s", err->message);
    }
}