Skip to content
Snippets Groups Projects
events.c 34.9 KiB
Newer Older
                clientShow(c, True);
            }
            break;
        case MENU_OP_SHADE:
        case MENU_OP_UNSHADE:
            if(c)
            {
                clientToggleShaded(c);
            }
            break;
        case MENU_OP_STICK:
        case MENU_OP_UNSTICK:
            if(c)
            {
                frameDraw(c);
                clientToggleSticky(c);
                clientClose(c);
static gboolean show_popup_cb(GtkWidget * widget, GdkEventButton * ev, gpointer data)
Olivier Fourdan's avatar
Olivier Fourdan committed
{
    Menu *menu;
    MenuOp ops;
    MenuOp insensitive;
    Client *c = NULL;
    gint x = ev->x_root;
    gint y = ev->y_root;

    DBG("entering show_popup_cb\n");

    if(((ev->button == 1) || (ev->button == 3)) && (c = (Client *) data))
    {
        c->button_pressed[MENU_BUTTON] = True;
        frameDraw(c);
        y = c->y;
        ops = MENU_OP_DELETE | MENU_OP_MINIMIZE_ALL;
            insensitive |= MENU_OP_DELETE;
        if(c->win_state & (WIN_STATE_MAXIMIZED | WIN_STATE_MAXIMIZED_HORIZ | WIN_STATE_MAXIMIZED_VERT))
            if(!CAN_MAXIMIZE_WINDOW(c))
            {
                insensitive |= MENU_OP_UNMAXIMIZE;
            }
            if(!CAN_MAXIMIZE_WINDOW(c))
            {
                insensitive |= MENU_OP_MAXIMIZE;
            }
        if(c->hidden)
            if(!CAN_HIDE_WINDOW(c))
            {
                insensitive |= MENU_OP_UNMINIMIZE;
            }
            if(!CAN_HIDE_WINDOW(c))
            {
                insensitive |= MENU_OP_MINIMIZE;
            }
                insensitive |= MENU_OP_UNSTICK;
                insensitive |= MENU_OP_STICK;
        }
    }
    else
    {
        return (TRUE);
    }

    if(button_handler_id)
    {
        g_signal_handler_disconnect(GTK_OBJECT(getDefaultGtkWidget()), button_handler_id);
    }
    button_handler_id = g_signal_connect(GTK_OBJECT(getDefaultGtkWidget()), "button_press_event", GTK_SIGNAL_FUNC(show_popup_cb), (gpointer) NULL);

        menu_event_window = None;
    }
Olivier Fourdan's avatar
Olivier Fourdan committed
    /* 
       Since all button press/release events are catched by the windows frames, there is some 
       side effect with GTK menu. When a menu is opened, any click on the window frame is not
       detected as a click outside the menu, and the menu doesn't close.
       To avoid this (painless but annoying) behaviour, we just setup a no event window that 
       "hides" the events to regular windows. 
       That might look tricky, but it's very efficient and save plenty of lines of complicated 
       code.
       Don't forget to delete that window once the menu is closed, though, or we'll get in 
       trouble.
     */
    menu_event_window = setTmpEventWin(NoEventMask);
    menu = menu_default(ops, insensitive, menu_callback, c);
    if(!menu_popup(menu, x, y, ev->button, ev->time))
        gdk_beep();
        c->button_pressed[MENU_BUTTON] = False;
        menu_event_window = None;
static gboolean set_reload(void)
{
    DBG("setting reload flag so all prefs will be reread at next event loop\n");
    reload = True;
    return (TRUE);
}

static gboolean set_dbl_click_time(void)
{
    GValue tmp_val = { 0, };
    DBG("setting dbl_click_time\n");

    g_value_init(&tmp_val, G_TYPE_INT);
    if(gdk_setting_get("gtk-double-click-time", &tmp_val))
        dbl_click_time = abs(g_value_get_int(&tmp_val));
static gboolean client_event_cb(GtkWidget * widget, GdkEventClient * ev)
Olivier Fourdan's avatar
Olivier Fourdan committed
{
    DBG("entering client_event_cb\n");

    if(!atom_rcfiles)
    {
        atom_rcfiles = gdk_atom_intern("_GTK_READ_RCFILES", FALSE);
    }

    if(ev->message_type == atom_rcfiles)
    {
        set_reload();
Olivier Fourdan's avatar
Olivier Fourdan committed
{
    GtkSettings *settings;
    button_handler_id = g_signal_connect(GTK_OBJECT(getDefaultGtkWidget()), "button_press_event", GTK_SIGNAL_FUNC(show_popup_cb), (gpointer) NULL);
    g_signal_connect(GTK_OBJECT(getDefaultGtkWidget()), "client_event", GTK_SIGNAL_FUNC(client_event_cb), (gpointer) NULL);

    settings = gtk_settings_get_default();
        g_signal_connect(settings, "notify::gtk-theme-name", G_CALLBACK(set_reload), NULL);
        g_signal_connect(settings, "notify::gtk-font-name", G_CALLBACK(set_reload), NULL);
        g_signal_connect(settings, "notify::gtk-double-click-time", G_CALLBACK(set_dbl_click_time), NULL);
Olivier Fourdan's avatar
Olivier Fourdan committed
}