Exemple #1
0
void wait_key(void)
{
    XEvent event;

    while(1)
    {
        XNextEvent(dpy, &event);

        if(event.type == KeyPress)
        {
            if(XkbKeycodeToKeysym(dpy, event.xkey.keycode, 0, 0) == opt_key)
                mainwindow_toggle(0);
        }
    }
}
Exemple #2
0
void build_mainwindow(void)
{
    guint ic;
  
    uri_regex_count = G_N_ELEMENTS(uri_patterns);
    uri_regex = g_new0(GRegex*, uri_regex_count);

    for(ic = 0; ic < uri_regex_count; ++ic)
    {
        GError *error = NULL;
        
        uri_regex[ic] = g_regex_new(uri_patterns[ic].pattern,
            uri_patterns[ic].flags | G_REGEX_OPTIMIZE, 0, &error);
        
        if(error)
        {
            g_message("%s", error->message);
            g_error_free (error);
        }
    }

    mainwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);

    gtk_widget_set_app_paintable(mainwindow, TRUE);
    gtk_widget_set_size_request(mainwindow, conf_get_width(), conf_get_height());
    gtk_window_set_decorated(GTK_WINDOW(mainwindow), FALSE);
    gtk_window_set_skip_taskbar_hint(GTK_WINDOW(mainwindow), TRUE);
    gtk_window_set_skip_pager_hint(GTK_WINDOW(mainwindow), TRUE);
    gtk_window_set_resizable(GTK_WINDOW(mainwindow), TRUE);
    mainwindow_reset_position();

    fullscreen = FALSE;
    toggled = FALSE;

    GtkAccelGroup* accel_group;
    GClosure *new_tab, *delete_tab, *next_tab, *prev_tab, *delete_all,
        *maximize, *copy, *paste;

    GClosure *goto_tab_closure[10];
    long i;

    accel_group = gtk_accel_group_new();
    gtk_window_add_accel_group(GTK_WINDOW(mainwindow), accel_group);

    maximize = g_cclosure_new_swap(G_CALLBACK(mainwindow_toggle_fullscreen),
        NULL, NULL);
    gtk_accel_group_connect(accel_group, GDK_F11, 0,
        GTK_ACCEL_VISIBLE, maximize);

    new_tab = g_cclosure_new_swap(G_CALLBACK(mainwindow_new_tab), 
        NULL, NULL);
    gtk_accel_group_connect(accel_group, 't', conf_get_key_mod(),
        GTK_ACCEL_VISIBLE, new_tab);

    delete_tab = g_cclosure_new_swap(G_CALLBACK(mainwindow_delete_tab), 
        NULL, NULL);
    gtk_accel_group_connect(accel_group, 'w', conf_get_key_mod(),
        GTK_ACCEL_VISIBLE, delete_tab);

    next_tab = g_cclosure_new_swap(G_CALLBACK(mainwindow_next_tab), 
        NULL, NULL);
    gtk_accel_group_connect(accel_group, GDK_Page_Up, conf_get_key_mod(),
        GTK_ACCEL_VISIBLE, next_tab);

    prev_tab = g_cclosure_new_swap(G_CALLBACK(mainwindow_prev_tab), 
        NULL, NULL);
    gtk_accel_group_connect(accel_group, GDK_Page_Down, conf_get_key_mod(),
        GTK_ACCEL_VISIBLE, prev_tab);

    delete_all = g_cclosure_new_swap(G_CALLBACK(mainwindow_destroy), 
        NULL, NULL);
    gtk_accel_group_connect(accel_group, 'q', conf_get_key_mod(),
        GTK_ACCEL_VISIBLE, delete_all);

    /* tab hotkeys, inspired by Tilda -- thanks to castorinop for the patch */
    for(i = 0; i < 10; i++)
    {
        goto_tab_closure[i] = g_cclosure_new_swap(G_CALLBACK(mainwindow_goto_tab),
            (gpointer) i, NULL);
        gtk_accel_group_connect(accel_group, '0' + ((i+1)%10), GDK_MOD1_MASK,
            GTK_ACCEL_VISIBLE, goto_tab_closure[i]);
    }

    copy = g_cclosure_new_swap(G_CALLBACK(mainwindow_copy), 
        NULL, NULL);
    gtk_accel_group_connect(accel_group, 'c', conf_get_key_mod(),
        GTK_ACCEL_VISIBLE, copy);

    paste = g_cclosure_new_swap(G_CALLBACK(mainwindow_paste), 
        NULL, NULL);
    gtk_accel_group_connect(accel_group, 'v', conf_get_key_mod(),
        GTK_ACCEL_VISIBLE, paste);

    activetab = -1;
    tabcount = 0;
    GtkVBox* mainbox = GTK_VBOX(gtk_vbox_new(FALSE, 0));
    
    tabbar = GTK_NOTEBOOK(gtk_notebook_new());
    
    g_signal_connect(G_OBJECT(tabbar), "switch-page",
        G_CALLBACK(mainwindow_switch_tab), NULL);

    if(conf_get_opacity() < 100)
    {
        GdkScreen *screen = gdk_screen_get_default();
        GdkColormap *colormap = gdk_screen_get_rgba_colormap(screen);
        screen_is_composited = (colormap != NULL
            && gdk_screen_is_composited(screen));

        if(screen_is_composited)
        {
            gtk_widget_set_colormap(GTK_WIDGET(mainwindow), colormap);
            gdk_screen_set_default_colormap(screen, colormap);
        }
    }

    gtk_box_pack_start(GTK_BOX(mainbox), GTK_WIDGET(tabbar), TRUE, TRUE, 0);

    mainwindow_create_tab();

    gtk_widget_show_all(GTK_WIDGET(mainbox));
    gtk_container_add(GTK_CONTAINER(mainwindow), GTK_WIDGET(mainbox));

    int border = conf_get_border();
    if(border == BORDER_THIN)
        gtk_container_set_border_width(GTK_CONTAINER(mainwindow), 1);
    else if(border == BORDER_THICK)
        gtk_container_set_border_width(GTK_CONTAINER(mainwindow), 5);
    if(border != BORDER_NONE)
        g_signal_connect(G_OBJECT(mainwindow), "expose-event",
            G_CALLBACK(mainwindow_expose_event), NULL);

    if(conf_get_auto_hide())
        g_signal_connect(G_OBJECT(mainwindow), "focus-out-event",
            G_CALLBACK(mainwindow_focus_out_event), NULL);
    g_signal_connect(G_OBJECT(mainwindow), "show", G_CALLBACK(mainwindow_show), 
        NULL);
    g_signal_connect(G_OBJECT(mainwindow), "destroy",
        G_CALLBACK(mainwindow_destroy), NULL);

    g_signal_connect_after(G_OBJECT(tabbar), "button_press_event", 
        G_CALLBACK(mainwindow_notebook_clicked), NULL);

    gtk_notebook_set_show_border(tabbar, FALSE);
    gtk_notebook_set_scrollable(tabbar, TRUE);
    if (conf_get_show_tab() == TABS_ONE|| conf_get_show_tab() == TABS_NEVER)
        gtk_notebook_set_show_tabs(tabbar, FALSE);
    gtk_notebook_set_tab_pos(tabbar, conf_get_tab_pos());
    gtk_notebook_set_homogeneous_tabs(tabbar, FALSE);

    XSetErrorHandler(handle_x_error);
    init_key();
    grab_key();
    g_thread_new("stjerm", (GThreadFunc)wait_key, NULL);
    
    // If stjerm has been started for the first time with --toggle, then
    // show the window straight away. Make haste!
    if(conf_get_toggled()) {
        mainwindow_toggle(1);
    }
}