Beispiel #1
0
// determine which monitor holds the active window, or failing that the mouse pointer
void monitor_active ( Display *display, workarea *mon )
{
    Screen *screen = DefaultScreenOfDisplay ( display );
    Window root    = RootWindow ( display, XScreenNumberOfScreen ( screen ) );
    int    x, y;

    Window id;
    Atom   type;
    int    count;
    if ( config.monitor >= 0 ) {
        if ( monitor_get_dimension ( display, screen, config.monitor, mon ) ) {
            return;
        }
        fprintf ( stderr, "Failed to find selected monitor.\n" );
    }
    if ( window_get_prop ( display, root, netatoms[_NET_ACTIVE_WINDOW], &type, &count, &id, sizeof ( Window ) )
         && type == XA_WINDOW && count > 0 ) {
        XWindowAttributes attr;
        if ( XGetWindowAttributes ( display, id, &attr ) ) {
            Window junkwin;
            if ( XTranslateCoordinates ( display, id, attr.root,
                                         -attr.border_width,
                                         -attr.border_width,
                                         &x, &y, &junkwin ) == True ) {
                monitor_dimensions ( display, screen, x, y, mon );
                return;
            }
        }
    }
    if ( pointer_get ( display, root, &x, &y ) ) {
        monitor_dimensions ( display, screen, x, y, mon );
        return;
    }

    monitor_dimensions ( display, screen, 0, 0, mon );
}
Beispiel #2
0
// determine which monitor holds the active window, or failing that the mouse pointer
void monitor_active ( workarea *mon )
{
    xcb_window_t root = xcb->screen->root;
    int          x, y;

    if ( config.monitor >= 0 ) {
        if ( monitor_get_dimension ( config.monitor, mon ) ) {
            return;
        }
        fprintf ( stderr, "Failed to find selected monitor.\n" );
    }
    if ( config.monitor == -3 ) {
        if ( pointer_get ( root, &x, &y ) ) {
            monitor_dimensions ( x, y, mon );
            mon->x = x;
            mon->y = y;
            return;
        }
    }
    // Get the current desktop.
    unsigned int current_desktop = 0;
    if ( config.monitor == -1 && xcb_ewmh_get_current_desktop_reply ( &xcb->ewmh,
                                                                      xcb_ewmh_get_current_desktop ( &xcb->ewmh, xcb->screen_nbr ),
                                                                      &current_desktop, NULL ) ) {
        xcb_get_property_cookie_t             c = xcb_ewmh_get_desktop_viewport ( &xcb->ewmh, xcb->screen_nbr );
        xcb_ewmh_get_desktop_viewport_reply_t vp;
        if ( xcb_ewmh_get_desktop_viewport_reply ( &xcb->ewmh, c, &vp, NULL ) ) {
            if ( current_desktop < vp.desktop_viewport_len ) {
                monitor_dimensions ( vp.desktop_viewport[current_desktop].x,
                                     vp.desktop_viewport[current_desktop].y, mon );
                xcb_ewmh_get_desktop_viewport_reply_wipe ( &vp );
                return;
            }
            xcb_ewmh_get_desktop_viewport_reply_wipe ( &vp );
        }
    }

    xcb_window_t active_window;
    if ( xcb_ewmh_get_active_window_reply ( &xcb->ewmh,
                                            xcb_ewmh_get_active_window ( &xcb->ewmh, xcb->screen_nbr ), &active_window, NULL ) ) {
        // get geometry.
        xcb_get_geometry_cookie_t c  = xcb_get_geometry ( xcb->connection, active_window );
        xcb_get_geometry_reply_t  *r = xcb_get_geometry_reply ( xcb->connection, c, NULL );
        if ( r ) {
            xcb_translate_coordinates_cookie_t ct = xcb_translate_coordinates ( xcb->connection, active_window, root, r->x, r->y );
            xcb_translate_coordinates_reply_t  *t = xcb_translate_coordinates_reply ( xcb->connection, ct, NULL );
            if ( t ) {
                if ( config.monitor == -2 ) {
                    // place the menu above the window
                    // if some window is focused, place menu above window, else fall
                    // back to selected monitor.
                    mon->x = t->dst_x - r->x;
                    mon->y = t->dst_y - r->y;
                    mon->w = r->width;
                    mon->h = r->height;
                    mon->t = r->border_width;
                    mon->b = r->border_width;
                    mon->l = r->border_width;
                    mon->r = r->border_width;
                    free ( r );
                    free ( t );
                    return;
                } else if ( config.monitor == -4 ){
                    monitor_dimensions ( t->dst_x, t->dst_y, mon );
                    free(r);
                    free(t);
                    return;

                }
            }
            free ( r );
        }
    }
    if ( pointer_get ( root, &x, &y ) ) {
        monitor_dimensions ( x, y, mon );
        return;
    }

    monitor_dimensions ( 0, 0, mon );
}