Example #1
0
static void edge_warp_move_ptr(void)
{
    gint x, y;
    const Rect* a;

    screen_pointer_pos(&x, &y);
    a = screen_physical_area_all_monitors();

    switch (edge_warp_dir) {
	case OB_DIRECTION_NORTH:
	    y = a->height - 1;
	    break;
	case OB_DIRECTION_EAST:
	    x = a->x;
	    break;
	case OB_DIRECTION_SOUTH:
	    y = a->y;
	    break;
	case OB_DIRECTION_WEST:
	    x = a->width - 1;
	    break;
	default:
        g_assert_not_reached();
    }

    XWarpPointer(obt_display, 0, obt_root(ob_screen), 0, 0, 0, 0, x, y);
}
Example #2
0
static guint32 pick_corner(gint x, gint y, gint cx, gint cy, gint cw, gint ch,
                           gboolean shaded)
{
    const Rect *full = screen_physical_area_all_monitors();
    if (cx < full->x) { cw = cw + cx - full->x; cx = full->x; }
    if (cy < full->y) { ch = ch + cy - full->y; cy = full->y; }
    if (cx + cw > full->x + full->width) cw = full->x + full->width - cx;
    if (cy + ch > full->y + full->height) ch = full->y + full->height - cy;

    /* let's make x and y client relative instead of screen relative */
    x = x - cx;
    y = ch - (y - cy); /* y is inverted, 0 is at the bottom of the window */

#define X x*ch/cw
#define A -4*X + 7*ch/3
#define B  4*X -15*ch/9
#define C -X/4 + 2*ch/3
#define D  X/4 + 5*ch/12
#define E  X/4 +   ch/3
#define F -X/4 + 7*ch/12
#define G  4*X - 4*ch/3
#define H -4*X + 8*ch/3
#define a (y > 5*ch/9)
#define b (x < 4*cw/9)
#define c (x > 5*cw/9)
#define d (y < 4*ch/9)

    /*
      Each of these defines (except X which is just there for fun), represents
      the equation of a line. The lines they represent are shown in the diagram
      below. Checking y against these lines, we are able to choose a region
      of the window as shown.

      +---------------------A-------|-------|-------B---------------------+
      |                     |A                     B|                     |
      |                     |A      |       |      B|                     |
      |                     | A                   B |                     |
      |                     | A     |       |     B |                     |
      |                     |  A                 B  |                     |
      |                     |  A    |       |    B  |                     |
      |        northwest    |   A     north     B   |   northeast         |
      |                     |   A   |       |   B   |                     |
      |                     |    A             B    |                     |
      C---------------------+----A--+-------+--B----+---------------------D
      |CCCCCCC              |     A           B     |              DDDDDDD|
      |       CCCCCCCC      |     A |       | B     |      DDDDDDDD       |
      |               CCCCCCC      A         B      DDDDDDD               |
      - - - - - - - - - - - +CCCCCCC+aaaaaaa+DDDDDDD+ - - - - - - - - - - - -
      |                     |       b       c       |                     | sh
      |             west    |       b  move c       |   east              | ad
      |                     |       b       c       |                     | ed
      - - - - - - - - - - - +EEEEEEE+ddddddd+FFFFFFF+- - - - - - - - - - -  -
      |               EEEEEEE      G         H      FFFFFFF               |
      |       EEEEEEEE      |     G |       | H     |      FFFFFFFF       |
      |EEEEEEE              |     G           H     |              FFFFFFF|
      E---------------------+----G--+-------+--H----+---------------------F
      |                     |    G             H    |                     |
      |                     |   G   |       |   H   |                     |
      |        southwest    |   G     south     H   |   southeast         |
      |                     |  G    |       |    H  |                     |
      |                     |  G                 H  |                     |
      |                     | G     |       |     H |                     |
      |                     | G                   H |                     |
      |                     |G      |       |      H|                     |
      |                     |G                     H|                     |
      +---------------------G-------|-------|-------H---------------------+
    */

    if (shaded) {
        /* for shaded windows, you can only resize west/east and move */
        if (b)
            return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_LEFT);
        if (c)
            return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_RIGHT);
        return OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE);
    }

    if (y < A && y >= C)
        return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPLEFT);
    else if (y >= A && y >= B && a)
        return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOP);
    else if (y < B && y >= D)
        return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPRIGHT);
    else if (y < C && y >= E && b)
        return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_LEFT);
    else if (y < D && y >= F && c)
        return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_RIGHT);
    else if (y < E && y >= G)
        return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT);
    else if (y < G && y < H && d)
        return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOM);
    else if (y >= H && y < F)
        return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT);
    else
        return OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE);

#undef X
#undef A
#undef B
#undef C
#undef D
#undef E
#undef F
#undef G
#undef H
#undef a
#undef b
#undef c
#undef d
}
Example #3
0
static void prompt_layout(ObPrompt *self)
{
    gint l, r, t, b;
    gint i;
    gint allbuttonsw, allbuttonsh, buttonx;
    gint w, h;
    gint maxw;

    RrMargins(prompt_a_bg, &l, &t, &r, &b);
    l += OUTSIDE_MARGIN;
    t += OUTSIDE_MARGIN;
    r += OUTSIDE_MARGIN;
    b += OUTSIDE_MARGIN;

    {
        const Rect *area = screen_physical_area_all_monitors();
        maxw = MIN(MAX_WIDTH, area->width*4/5);
    }

    /* find the button sizes and how much space we need for them */
    allbuttonsw = allbuttonsh = 0;
    for (i = 0; i < self->n_buttons; ++i) {
        gint bw, bh;

        prompt_a_button->texture[0].data.text.string = self->button[i].text;
        prompt_a_focus->texture[0].data.text.string = self->button[i].text;
        prompt_a_press->texture[0].data.text.string = self->button[i].text;
        prompt_a_pfocus->texture[0].data.text.string = self->button[i].text;
        RrMinSize(prompt_a_button, &bw, &bh);
        self->button[i].width = bw;
        self->button[i].height = bh;
        RrMinSize(prompt_a_focus, &bw, &bh);
        self->button[i].width = MAX(self->button[i].width, bw);
        self->button[i].height = MAX(self->button[i].height, bh);
        RrMinSize(prompt_a_press, &bw, &bh);
        self->button[i].width = MAX(self->button[i].width, bw);
        self->button[i].height = MAX(self->button[i].height, bh);
        RrMinSize(prompt_a_pfocus, &bw, &bh);
        self->button[i].width = MAX(self->button[i].width, bw);
        self->button[i].height = MAX(self->button[i].height, bh);

        self->button[i].width += BUTTON_HMARGIN * 2;
        self->button[i].height += BUTTON_VMARGIN * 2;

        allbuttonsw += self->button[i].width + (i > 0 ? BUTTON_SEPARATION : 0);
        allbuttonsh = MAX(allbuttonsh, self->button[i].height);
    }

    self->msg_wbound = MAX(allbuttonsw, maxw);

    /* measure the text message area */
    prompt_a_msg->texture[0].data.text.string = self->msg.text;
    prompt_a_msg->texture[0].data.text.maxwidth = self->msg_wbound;
    RrMinSize(prompt_a_msg, &self->msg.width, &self->msg.height);

    /* width and height inside the outer margins */
    w = MAX(self->msg.width, allbuttonsw);
    h = self->msg.height + MSG_BUTTON_SEPARATION + allbuttonsh;

    /* position the text message */
    self->msg.x = l + (w - self->msg.width) / 2;
    self->msg.y = t;

    /* position the button buttons on the right of the dialog */
    buttonx = l + w;
    for (i = self->n_buttons - 1; i >= 0; --i) {
        self->button[i].x = buttonx - self->button[i].width;
        buttonx -= self->button[i].width + BUTTON_SEPARATION;
        self->button[i].y = t + h - allbuttonsh;
        self->button[i].y += (allbuttonsh - self->button[i].height) / 2;
    }

    /* size and position the toplevel window */
    prompt_resize(self, w + l + r, h + t + b);

    /* move and resize the internal windows */
    XMoveResizeWindow(obt_display, self->msg.window,
                      self->msg.x, self->msg.y,
                      self->msg.width, self->msg.height);
    for (i = 0; i < self->n_buttons; ++i)
        XMoveResizeWindow(obt_display, self->button[i].window,
                          self->button[i].x, self->button[i].y,
                          self->button[i].width, self->button[i].height);
}