Ejemplo n.º 1
0
static void i3_on_workspace_clicked (GtkWidget *button, gpointer data)
{
    i3WorkspacesPlugin *i3_workspaces = (i3WorkspacesPlugin *)data;

    gint button_index = 0;
    gint i;
    for (i = 1; i < I3_WORKSPACE_N; i++)
    {
        if (i3_workspaces->buttons[i] == button)
        {
            button_index = i;
            break;
        }
    }
    g_printf("Click %i\n", button_index);
    i3wm_goto_workspace(i3_workspaces->i3wm, button_index);
}
/**
 * on_workspace_scrolled:
 * @ebox: the plugin's event box
 * @ev: the event data
 * @data: the workspace plugin
 *
 * Workspace scroll event handler.
 *
 * Returns: TRUE to stop event propogation
 */
static gboolean
on_workspace_scrolled(GtkWidget *ebox, GdkEventScroll *ev, gpointer data)
{
    i3WorkspacesPlugin *i3_workspaces = (i3WorkspacesPlugin *)data;

    GList *wlist = g_hash_table_get_keys(i3_workspaces->workspace_buttons);
    wlist = g_list_sort(wlist, (GCompareFunc) i3wm_workspace_cmp);

    /* Find the focused workspace */
    i3workspace *workspace = NULL;
    GList *witem = NULL;
    for (witem = wlist; witem != NULL; witem = witem->next)
    {
        workspace = (i3workspace *) witem->data;
        if (workspace->focused)
            break;
    }

    if (witem == NULL)
        return FALSE;

    if (ev->direction == GDK_SCROLL_DOWN)
        witem = witem->next;
    else if (ev->direction == GDK_SCROLL_UP)
        witem = witem->prev;
    else
        return FALSE;

    if (witem == NULL)
        return FALSE;

    workspace = (i3workspace *) witem->data;

    GError *err = NULL;
    i3wm_goto_workspace(i3_workspaces->i3wm, workspace, &err);
    if (err != NULL)
    {
        fprintf(stderr, "%s", err->message);
    }
    return TRUE;
}
/**
 * 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);
    }
}