Skip to content
Snippets Groups Projects
events.c 42 KiB
Newer Older
            TRACE("client \"%s\" (0x%lx) has received a net_wm_strut notify", c->name, c->window);
        else if(ev->atom == wm_colormap_windows)
        {
            clientUpdateColormaps(c);
            if(c == clientGetFocus())
            {
                clientInstallColormaps(c);
#ifdef HAVE_STARTUP_NOTIFICATION
        else if(ev->atom == net_startup_id)
        {
            if(c->startup_id)
            {
                free(c->startup_id);
                c->startup_id = NULL;
            }
Olivier Fourdan's avatar
Olivier Fourdan committed
            getWindowStartupId(dpy, c->window, &c->startup_id);
Olivier Fourdan's avatar
Olivier Fourdan committed
    }
    else if(ev->atom == gnome_panel_desktop_area)
Olivier Fourdan's avatar
Olivier Fourdan committed
    {
        TRACE("root has received a gnome_panel_desktop_area notify");
        getGnomeDesktopMargins(dpy, screen, gnome_margins);
        workspaceUpdateArea(margins, gnome_margins);
static inline void handleClientMessage(XClientMessageEvent * ev)
Olivier Fourdan's avatar
Olivier Fourdan committed
{
    Client *c;

    TRACE("entering handleClientMessage");
Olivier Fourdan's avatar
Olivier Fourdan committed

    c = clientGetFromWindow(ev->window, WINDOW);
    if(c)
    {
        if((ev->message_type == wm_change_state) && (ev->format == 32) && (ev->data.l[0] == IconicState))
            TRACE("client \"%s\" (0x%lx) has received a wm_change_state event", c->name, c->window);
            if (!CLIENT_FLAG_TEST(c, CLIENT_FLAG_HIDDEN))
            {
                clientHide(c, c->win_workspace, TRUE);
           }
        else if((ev->message_type == win_state) && (ev->format == 32))
Olivier Fourdan's avatar
Olivier Fourdan committed
        {
            TRACE("client \"%s\" (0x%lx) has received a win_state event", c->name, c->window);
            clientUpdateWinState(c, ev);
Olivier Fourdan's avatar
Olivier Fourdan committed
        }
        else if((ev->message_type == win_layer) && (ev->format == 32))
        {
            TRACE("client \"%s\" (0x%lx) has received a win_layer event", c->name, c->window);
            if (ev->data.l[0] != c->win_layer)
            {
                clientSetLayer(c, ev->data.l[0]);
                clientSetNetState(c);
            }
Olivier Fourdan's avatar
Olivier Fourdan committed
        }
        else if((ev->message_type == win_workspace) && (ev->format == 32) && !clientIsTransient(c))
            TRACE("client \"%s\" (0x%lx) has received a win_workspace event", c->name, c->window);
            if (ev->data.l[0] != c->win_workspace)
            {
                clientSetWorkspace(c, ev->data.l[0], TRUE);
            }
        }
        else if((ev->message_type == net_wm_desktop) && (ev->format == 32))
        {
            TRACE("client \"%s\" (0x%lx) has received a net_wm_desktop event", c->name, c->window);
            if(ev->data.l[0] == ALL_WORKSPACES)
                if (CLIENT_FLAG_TEST_AND_NOT(c, CLIENT_FLAG_HAS_STICK, CLIENT_FLAG_STICKY))
                {
                    clientStick(c, TRUE);
                    frameDraw(c, FALSE, FALSE);
                }
            else if (!clientIsTransient(c))
                if (CLIENT_FLAG_TEST_ALL(c, CLIENT_FLAG_HAS_STICK | CLIENT_FLAG_STICKY))
                {
                    clientUnstick(c, TRUE);
                    frameDraw(c, FALSE, FALSE);
                }
                if(ev->data.l[0] != c->win_workspace)
                {
                    clientSetWorkspace(c, ev->data.l[0], TRUE);
                }
Olivier Fourdan's avatar
Olivier Fourdan committed
        else if((ev->message_type == net_close_window) && (ev->format == 32))
            TRACE("client \"%s\" (0x%lx) has received a net_close_window event", c->name, c->window);
Olivier Fourdan's avatar
Olivier Fourdan committed
        else if((ev->message_type == net_wm_state) && (ev->format == 32))
        {
            TRACE("client \"%s\" (0x%lx) has received a net_wm_state event", c->name, c->window);
Olivier Fourdan's avatar
Olivier Fourdan committed
        else if((ev->message_type == net_wm_moveresize) && (ev->format == 32))
        {
            TRACE("client \"%s\" (0x%lx) has received a net_wm_moveresize event", c->name, c->window);
Olivier Fourdan's avatar
Olivier Fourdan committed
            g_message(_("%s: Operation not supported (yet)\n"), g_get_prgname());
Olivier Fourdan's avatar
Olivier Fourdan committed
        else if((ev->message_type == net_active_window) && (ev->format == 32))
        {
            TRACE("client \"%s\" (0x%lx) has received a net_active_window event", c->name, c->window);
Olivier Fourdan's avatar
Olivier Fourdan committed
    }
    else
    {
        if(((ev->message_type == win_workspace) || (ev->message_type == net_current_desktop)) && (ev->format == 32))
            TRACE("root has received a win_workspace or a net_current_desktop event");
Olivier Fourdan's avatar
Olivier Fourdan committed
        }
        else if(((ev->message_type == win_workspace_count) || (ev->message_type == net_number_of_desktops)) && (ev->format == 32))
        {
            TRACE("root has received a win_workspace_count event");
            if (ev->data.l[0] != params.workspace_count)
            {
                workspaceSetCount(ev->data.l[0]);
            }
            TRACE("unidentified client message for window 0x%lx", ev->window);
static inline void handleShape(XShapeEvent * ev)
Olivier Fourdan's avatar
Olivier Fourdan committed
{
    Client *c;

Olivier Fourdan's avatar
Olivier Fourdan committed

    c = clientGetFromWindow(ev->window, WINDOW);
    if(c)
    {
        frameDraw(c, FALSE, TRUE);
static inline void handleColormapNotify(XColormapEvent * ev)
    TRACE("entering handleColormapNotify");
    c = clientGetFromWindow(ev->window, WINDOW);
    if((c) && (ev->window == c->window) && (ev->new))
Olivier Fourdan's avatar
Olivier Fourdan committed
void handleEvent(XEvent * ev)
{
Olivier Fourdan's avatar
Olivier Fourdan committed

Olivier Fourdan's avatar
Olivier Fourdan committed
    switch (ev->type)
    {
    case KeyPress:
        handleKeyPress((XKeyEvent *) ev);
        break;
    case ButtonPress:
        handleButtonPress((XButtonEvent *) ev);
        break;
    case ButtonRelease:
        handleButtonRelease((XButtonEvent *) ev);
        break;
    case DestroyNotify:
        handleDestroyNotify((XDestroyWindowEvent *) ev);
        break;
    case UnmapNotify:
        handleUnmapNotify((XUnmapEvent *) ev);
        break;
    case MapRequest:
        handleMapRequest((XMapRequestEvent *) ev);
        break;
    case ConfigureRequest:
        handleConfigureRequest((XConfigureRequestEvent *) ev);
        break;
    case EnterNotify:
        handleEnterNotify((XCrossingEvent *) ev);
        break;
    case FocusIn:
        handleFocusIn((XFocusChangeEvent *) ev);
        break;
    case FocusOut:
        handleFocusOut((XFocusChangeEvent *) ev);
        break;
    case PropertyNotify:
        handlePropertyNotify((XPropertyEvent *) ev);
        break;
    case ClientMessage:
        handleClientMessage((XClientMessageEvent *) ev);
        break;
    case ColormapNotify:
        handleColormapNotify((XColormapEvent *) ev);
        break;
    default:
        if(shape && (ev->type == shape_event))
        {
            handleShape((XShapeEvent *) ev);
        }
Olivier Fourdan's avatar
Olivier Fourdan committed
    }
Olivier Fourdan's avatar
Olivier Fourdan committed
    {
            reloadSettings(UPDATE_ALL);
Olivier Fourdan's avatar
Olivier Fourdan committed
            gtk_main_quit();
GtkToXEventFilterStatus xfwm4_event_filter(XEvent * xevent, gpointer data)
Olivier Fourdan's avatar
Olivier Fourdan committed
{
    TRACE("entering xfwm4_event_filter");
Olivier Fourdan's avatar
Olivier Fourdan committed
    handleEvent(xevent);
    TRACE("leaving xfwm4_event_filter");
Olivier Fourdan's avatar
Olivier Fourdan committed
    return XEV_FILTER_STOP;
}

Olivier Fourdan's avatar
Olivier Fourdan committed

static void menu_callback(Menu * menu, MenuOp op, Window client_xwindow, gpointer menu_data, gpointer item_data)
Olivier Fourdan's avatar
Olivier Fourdan committed
{
Olivier Fourdan's avatar
Olivier Fourdan committed
    Client *c = NULL;
        menu_event_window = None;
    }

Olivier Fourdan's avatar
Olivier Fourdan committed
    {
        c = (Client *) menu_data;
        c = clientGetFromWindow(c->window, WINDOW);
        c->button_pressed[MENU_BUTTON] = FALSE;
Olivier Fourdan's avatar
Olivier Fourdan committed
    }
Olivier Fourdan's avatar
Olivier Fourdan committed
    switch (op)
    {
    case MENU_OP_QUIT:
        gtk_main_quit();
        break;
    case MENU_OP_MAXIMIZE:
    case MENU_OP_UNMAXIMIZE:
        {
            clientToggleMaximized(c, WIN_STATE_MAXIMIZED);
        }
        break;
    case MENU_OP_MINIMIZE:
            clientHide(c, c->win_workspace, TRUE);
        clientHideAll(c, c->win_workspace);
        frameDraw(c, FALSE, FALSE);
        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;


    if(((ev->button == 1) || (ev->button == 3)) && (c = (Client *) data))
    {
        c->button_pressed[MENU_BUTTON] = TRUE;
        frameDraw(c, FALSE, FALSE);
        ops = MENU_OP_DELETE | MENU_OP_MINIMIZE_ALL;
        if(!CLIENT_FLAG_TEST(c, CLIENT_FLAG_HAS_CLOSE))
            insensitive |= MENU_OP_DELETE;
        if(CLIENT_FLAG_TEST(c, CLIENT_FLAG_MAXIMIZED))
            if(!CLIENT_CAN_MAXIMIZE_WINDOW(c))
            if(!CLIENT_CAN_MAXIMIZE_WINDOW(c))
        if(CLIENT_FLAG_TEST(c, CLIENT_FLAG_HIDDEN))
            if(!CLIENT_CAN_HIDE_WINDOW(c))
            if(!CLIENT_CAN_HIDE_WINDOW(c))
        if(CLIENT_FLAG_TEST(c, CLIENT_FLAG_SHADED))
        if(CLIENT_FLAG_TEST(c, CLIENT_FLAG_STICKY))
            if(!CLIENT_FLAG_TEST(c, CLIENT_FLAG_HAS_STICK))
                insensitive |= MENU_OP_UNSTICK;
            if(!CLIENT_FLAG_TEST(c, CLIENT_FLAG_HAS_STICK))
                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;
    }
    /*
       Since all button press/release events are catched by the windows frames, there is some
Olivier Fourdan's avatar
Olivier Fourdan committed
       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
Olivier Fourdan's avatar
Olivier Fourdan committed
       code.
       Don't forget to delete that window once the menu is closed, though, or we'll get in
Olivier Fourdan's avatar
Olivier Fourdan committed
       trouble.
     */
    menu_event_window = setTmpEventWin(NoEventMask);
    menu = menu_default(ops, insensitive, menu_callback, c);
    if(!menu_popup(menu, x, y, ev->button, ev->time))
        c->button_pressed[MENU_BUTTON] = FALSE;
        frameDraw(c, FALSE, FALSE);
        menu_event_window = None;
static gboolean set_reload(void)
{
    TRACE("setting reload flag so all prefs will be reread at next event loop");
    return (TRUE);
}

static gboolean dbl_click_time(void)
{
    GValue tmp_val = { 0, };

    g_value_init(&tmp_val, G_TYPE_INT);
    if(gdk_setting_get("gtk-double-click-time", &tmp_val))
        params.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
{

    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(dbl_click_time), NULL);
Olivier Fourdan's avatar
Olivier Fourdan committed
}