Exemplo n.º 1
0
ObMenuFrame* menu_frame_new(ObMenu *menu, guint show_from, ObClient *client)
{
    ObMenuFrame *self;
    XSetWindowAttributes attr;

    self = g_slice_new0(ObMenuFrame);
    self->obwin.type = OB_WINDOW_CLASS_MENUFRAME;
    self->menu = menu;
    self->selected = NULL;
    self->client = client;
    self->direction_right = TRUE;
    self->show_from = show_from;

    attr.event_mask = FRAME_EVENTMASK;
    self->window = createWindow(obt_root(ob_screen),
                                CWEventMask, &attr);

    /* make it a popup menu type window */
    OBT_PROP_SET32(self->window, NET_WM_WINDOW_TYPE, ATOM,
                   OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_POPUP_MENU));

    XSetWindowBorderWidth(obt_display, self->window, ob_rr_theme->mbwidth);
    XSetWindowBorder(obt_display, self->window,
                     RrColorPixel(ob_rr_theme->menu_border_color));

    self->a_items = RrAppearanceCopy(ob_rr_theme->a_menu);

    window_add(&self->window, MENUFRAME_AS_WINDOW(self));
    stacking_add(MENUFRAME_AS_WINDOW(self));

    return self;
}
Exemplo n.º 2
0
ObPopup *popup_new(void)
{
    XSetWindowAttributes attrib;
    ObPopup *self = g_slice_new0(ObPopup);

    self->obwin.type = OB_WINDOW_CLASS_INTERNAL;
    self->gravity = NorthWestGravity;
    self->x = self->y = self->textw = self->h = 0;
    self->a_bg = RrAppearanceCopy(ob_rr_theme->osd_bg);
    self->a_text = RrAppearanceCopy(ob_rr_theme->osd_hilite_label);
    self->iconwm = self->iconhm = 1;

    attrib.override_redirect = True;
    self->bg = XCreateWindow(obt_display, obt_root(ob_screen),
                             0, 0, 1, 1, 0, RrDepth(ob_rr_inst),
                             InputOutput, RrVisual(ob_rr_inst),
                             CWOverrideRedirect, &attrib);

    self->text = XCreateWindow(obt_display, self->bg,
                               0, 0, 1, 1, 0, RrDepth(ob_rr_inst),
                               InputOutput, RrVisual(ob_rr_inst), 0, NULL);

    XSetWindowBorderWidth(obt_display, self->bg, ob_rr_theme->obwidth);
    XSetWindowBorder(obt_display, self->bg,
                     RrColorPixel(ob_rr_theme->osd_border_color));

    XMapWindow(obt_display, self->text);

    stacking_add(INTERNAL_AS_WINDOW(self));
    window_add(&self->bg, INTERNAL_AS_WINDOW(self));
    return self;
}
Exemplo n.º 3
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);
}
Exemplo n.º 4
0
static void prompt_resize(ObPrompt *self, gint w, gint h)
{
    XConfigureRequestEvent req;
    XSizeHints hints;

    self->width = w;
    self->height = h;

    /* the user can't resize the prompt */
    hints.flags = PMinSize | PMaxSize;
    hints.min_width = hints.max_width = w;
    hints.min_height = hints.max_height = h;
    XSetWMNormalHints(obt_display, self->super.window, &hints);

    if (self->mapped) {
        /* send a configure request like a normal client would */
        req.type = ConfigureRequest;
        req.display = obt_display;
        req.parent = obt_root(ob_screen);
        req.window = self->super.window;
        req.width = w;
        req.height = h;
        req.value_mask = CWWidth | CWHeight;
        XSendEvent(req.display, req.window, FALSE, StructureNotifyMask,
                   (XEvent*)&req);
    }
    else
        XResizeWindow(obt_display, self->super.window, w, h);
}
Exemplo n.º 5
0
void prompt_show(ObPrompt *self, ObClient *parent, gboolean modal)
{
    gint i;

    if (self->mapped) {
        /* activate the prompt */
        OBT_PROP_MSG(ob_screen, self->super.window, NET_ACTIVE_WINDOW,
                     1, /* from an application.. */
                     event_time(),
                     0,
                     0, 0);
        return;
    }

    /* set the focused button (if not found then the first button is used) */
    self->focus = &self->button[0];
    for (i = 0; i < self->n_buttons; ++i)
        if (self->button[i].result == self->default_result) {
            self->focus = &self->button[i];
            break;
        }

    if (parent) {
        Atom states[1];
        gint nstates;
        Window p;
        XWMHints h;

        if (parent->group) {
            /* make it transient for the window's group */
            h.flags = WindowGroupHint;
            h.window_group = parent->group->leader;
            p = obt_root(ob_screen);
        }
        else {
            /* make it transient for the window directly */
            h.flags = 0;
            p = parent->window;
        }

        XSetWMHints(obt_display, self->super.window, &h);
        OBT_PROP_SET32(self->super.window, WM_TRANSIENT_FOR, WINDOW, p);

        states[0] = OBT_PROP_ATOM(NET_WM_STATE_MODAL);
        nstates = (modal ? 1 : 0);
        OBT_PROP_SETA32(self->super.window, NET_WM_STATE, ATOM,
                        states, nstates);
    }
    else
        OBT_PROP_ERASE(self->super.window, WM_TRANSIENT_FOR);

    /* set up the dialog and render it */
    prompt_layout(self);
    render_all(self);

    client_manage(self->super.window, self);

    self->mapped = TRUE;
}
Exemplo n.º 6
0
ObPrompt* prompt_new(const gchar *msg, const gchar *title,
                     const ObPromptAnswer *answers, gint n_answers,
                     gint default_result, gint cancel_result,
                     ObPromptCallback func, ObPromptCleanup cleanup,
                     gpointer data)
{
    ObPrompt *self;
    XSetWindowAttributes attrib;
    gint i;

    attrib.override_redirect = FALSE;

    self = g_slice_new0(ObPrompt);
    self->ref = 1;
    self->func = func;
    self->cleanup = cleanup;
    self->data = data;
    self->default_result = default_result;
    self->cancel_result = cancel_result;
    self->super.type = OB_WINDOW_CLASS_PROMPT;
    self->super.window = XCreateWindow(obt_display, obt_root(ob_screen),
                                       0, 0, 1, 1, 0,
                                       CopyFromParent, InputOutput,
                                       CopyFromParent,
                                       CWOverrideRedirect,
                                       &attrib);
    self->ic = obt_keyboard_context_new(self->super.window,
                                        self->super.window);

    /* make it a dialog type window */
    OBT_PROP_SET32(self->super.window, NET_WM_WINDOW_TYPE, ATOM,
                   OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG));

    /* set the window's title */
    if (title)
        OBT_PROP_SETS(self->super.window, NET_WM_NAME, utf8, title);

    /* listen for key presses on the window */
    self->event_mask = KeyPressMask;

    /* set up the text message widow */
    self->msg.text = g_strdup(msg);
    self->msg.window = XCreateWindow(obt_display, self->super.window,
                                     0, 0, 1, 1, 0,
                                     CopyFromParent, InputOutput,
                                     CopyFromParent, 0, NULL);
    XMapWindow(obt_display, self->msg.window);

    /* set up the buttons from the answers */

    self->n_buttons = n_answers;
    if (!self->n_buttons)
        self->n_buttons = 1;

    self->button = g_new0(ObPromptElement, self->n_buttons);

    if (n_answers == 0) {
        g_assert(self->n_buttons == 1); /* should be set to this above.. */
        self->button[0].text = g_strdup(_("OK"));
    }
    else {
        g_assert(self->n_buttons > 0);
        for (i = 0; i < self->n_buttons; ++i) {
            self->button[i].text = g_strdup(answers[i].text);
            self->button[i].result = answers[i].result;
        }
    }

    for (i = 0; i < self->n_buttons; ++i) {
        self->button[i].window = XCreateWindow(obt_display, self->super.window,
                                               0, 0, 1, 1, 0,
                                               CopyFromParent, InputOutput,
                                               CopyFromParent, 0, NULL);
        XMapWindow(obt_display, self->button[i].window);
        window_add(&self->button[i].window, PROMPT_AS_WINDOW(self));

        /* listen for button presses on the buttons */
        XSelectInput(obt_display, self->button[i].window,
                     ButtonPressMask | ButtonReleaseMask | ButtonMotionMask);
    }

    prompt_list = g_list_prepend(prompt_list, self);

    return self;
}