Esempio n. 1
0
gboolean prompt_key_event(ObPrompt *self, XEvent *e)
{
    gboolean shift;
    guint shift_mask, mods;
    KeySym sym;

    if (e->type != KeyPress) return FALSE;

    shift_mask = obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_SHIFT);
    mods = obt_keyboard_only_modmasks(e->xkey.state);
    shift = !!(mods & shift_mask);

    /* only accept shift */
    if (mods != 0 && mods != shift_mask)
        return FALSE;

    sym = obt_keyboard_keypress_to_keysym(e);

    if (sym == XK_Escape)
        prompt_cancel(self);
    else if (sym == XK_Return || sym == XK_KP_Enter || sym == XK_space)
        prompt_run_callback(self, self->focus->result);
    else if (sym == XK_Tab || sym == XK_Left || sym == XK_Right) {
        gint i;
        gboolean left;
        ObPromptElement *oldfocus;

        left = (sym == XK_Left) || ((sym == XK_Tab) && shift);
        oldfocus = self->focus;

        for (i = 0; i < self->n_buttons; ++i)
            if (self->focus == &self->button[i]) break;
        i += (left ? -1 : 1);
        if (i < 0) i = self->n_buttons - 1;
        else if (i >= self->n_buttons) i = 0;
        self->focus = &self->button[i];

        if (oldfocus != self->focus) render_button(self, oldfocus);
        render_button(self, self->focus);
    }
    return TRUE;
}
Esempio n. 2
0
gboolean moveresize_event(XEvent *e)
{
    gboolean used = FALSE;

    if (!moveresize_in_progress) return FALSE;

    if (e->type == ButtonPress) {
        if (!button) {
            start_x = e->xbutton.x_root;
            start_y = e->xbutton.y_root;
            button = e->xbutton.button; /* this will end it now */
        }
        used = e->xbutton.button == button;
    } else if (e->type == ButtonRelease) {
        if (!button || e->xbutton.button == button) {
            moveresize_end(FALSE);
            used = TRUE;
        }
    } else if (e->type == MotionNotify) {
        if (moving) {
            cur_x = start_cx + e->xmotion.x_root - start_x;
            cur_y = start_cy + e->xmotion.y_root - start_y;
            do_move(FALSE, 0);
            do_edge_warp(e->xmotion.x_root, e->xmotion.y_root);
        } else {
            gint dw, dh;
            ObDirection dir;

            if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPLEFT)) {
                dw = -(e->xmotion.x_root - start_x);
                dh = -(e->xmotion.y_root - start_y);
                dir = OB_DIRECTION_NORTHWEST;
            } else if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOP)) {
                dw = 0;
                dh = -(e->xmotion.y_root - start_y);
                dir = OB_DIRECTION_NORTH;
            } else if (corner ==
                       OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPRIGHT)) {
                dw = (e->xmotion.x_root - start_x);
                dh = -(e->xmotion.y_root - start_y);
                dir = OB_DIRECTION_NORTHEAST;
            } else if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_RIGHT)) {
                dw = (e->xmotion.x_root - start_x);
                dh = 0;
                dir = OB_DIRECTION_EAST;
            } else if (corner ==
                       OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT)) {
                dw = (e->xmotion.x_root - start_x);
                dh = (e->xmotion.y_root - start_y);
                dir = OB_DIRECTION_SOUTHEAST;
            } else if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOM))
            {
                dw = 0;
                dh = (e->xmotion.y_root - start_y);
                dir = OB_DIRECTION_SOUTH;
            } else if (corner ==
                       OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT)) {
                dw = -(e->xmotion.x_root - start_x);
                dh = (e->xmotion.y_root - start_y);
                dir = OB_DIRECTION_SOUTHWEST;
            } else if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_LEFT)) {
                dw = -(e->xmotion.x_root - start_x);
                dh = 0;
                dir = OB_DIRECTION_WEST;
            } else if (corner ==
                       OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_KEYBOARD)) {
                dw = (e->xmotion.x_root - start_x);
                dh = (e->xmotion.y_root - start_y);
                dir = OB_DIRECTION_SOUTHEAST;
            } else
                g_assert_not_reached();

            /* override the client's max state if desired */
            if (ABS(dw) >= config_resist_edge) {
                if (moveresize_client->max_horz) {
                    /* unmax horz */
                    was_max_horz = TRUE;
                    pre_max_area.x = moveresize_client->pre_max_area.x;
                    pre_max_area.width = moveresize_client->pre_max_area.width;

                    moveresize_client->pre_max_area.x = cur_x;
                    moveresize_client->pre_max_area.width = cur_w;
                    client_maximize(moveresize_client, FALSE, 1);
                }
            }
            else if (was_max_horz && !moveresize_client->max_horz) {
                /* remax horz and put the premax back */
                client_maximize(moveresize_client, TRUE, 1);
                moveresize_client->pre_max_area.x = pre_max_area.x;
                moveresize_client->pre_max_area.width = pre_max_area.width;
            }

            if (ABS(dh) >= config_resist_edge) {
                if (moveresize_client->max_vert) {
                    /* unmax vert */
                    was_max_vert = TRUE;
                    pre_max_area.y = moveresize_client->pre_max_area.y;
                    pre_max_area.height =
                        moveresize_client->pre_max_area.height;

                    moveresize_client->pre_max_area.y = cur_y;
                    moveresize_client->pre_max_area.height = cur_h;
                    client_maximize(moveresize_client, FALSE, 2);
                }
            }
            else if (was_max_vert && !moveresize_client->max_vert) {
                /* remax vert and put the premax back */
                client_maximize(moveresize_client, TRUE, 2);
                moveresize_client->pre_max_area.y = pre_max_area.y;
                moveresize_client->pre_max_area.height = pre_max_area.height;
            }

            dw -= cur_w - start_cw;
            dh -= cur_h - start_ch;

            calc_resize(FALSE, 0, &dw, &dh, dir);
            cur_w += dw;
            cur_h += dh;

            if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPLEFT) ||
                corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_LEFT) ||
                corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT))
            {
                cur_x -= dw;
            }
            if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPLEFT) ||
                corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOP) ||
                corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPRIGHT))
            {
                cur_y -= dh;
            }

            do_resize();
        }
        used = TRUE;
    } else if (e->type == KeyPress) {
        KeySym sym = obt_keyboard_keypress_to_keysym(e);

        if (sym == XK_Escape) {
            moveresize_end(TRUE);
            used = TRUE;
        } else if (sym == XK_Return || sym == XK_KP_Enter) {
            moveresize_end(FALSE);
            used = TRUE;
        } else if (sym == XK_Right || sym == XK_Left ||
                   sym == XK_Up || sym == XK_Down)
        {
            if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_KEYBOARD)) {
                resize_with_keys(sym, e->xkey.state);
                used = TRUE;
            } else if (corner ==
                       OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE_KEYBOARD))
            {
                move_with_keys(sym, e->xkey.state);
                used = TRUE;
            }
        }
    }
#ifdef SYNC
    else if (e->type == obt_display_extension_sync_basep + XSyncAlarmNotify)
    {
        waiting_for_sync = 0; /* we got our sync... */
        do_resize(); /* ...so try resize if there is more change pending */
        used = TRUE;
    }
#endif

    if (used && moveresize_client == focus_client)
        event_update_user_time();

    return used;
}