Skip to content

Commit

Permalink
- add Application::get_monitor_rects
Browse files Browse the repository at this point in the history
  • Loading branch information
dk committed Oct 28, 2013
1 parent 957bbfc commit 918ab4f
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 2 deletions.
31 changes: 31 additions & 0 deletions Application.c
Expand Up @@ -647,6 +647,37 @@ Application_get_modal_window( Handle self, int modalFlag, Bool topMost)
return nilHandle;
}

SV *
Application_get_monitor_rects( Handle self)
{
int i, nrects;
Rect2 * rects = apc_application_get_monitor_rects(self, &nrects);
AV * ret = newAV();
for ( i = 0; i < nrects; i++) {
AV * rect = newAV();
av_push( rect, newSViv( rects[i].x));
av_push( rect, newSViv( rects[i].y));
av_push( rect, newSViv( rects[i].width));
av_push( rect, newSViv( rects[i].height));
av_push( ret, newRV_noinc(( SV *) rect));
}
free(rects);

/* .. or return at least the current size */
if ( nrects == 0) {
AV * rect = newAV();
Point sz = apc_application_get_size(self);
av_push( rect, newSViv( 0));
av_push( rect, newSViv( 0));
av_push( rect, newSViv( sz.x));
av_push( rect, newSViv( sz.y));
av_push( ret, newRV_noinc(( SV *) rect));
}

return newRV_noinc(( SV *) ret);
}


Handle
Application_get_parent( Handle self)
{
Expand Down
1 change: 1 addition & 0 deletions Application.cls
Expand Up @@ -89,6 +89,7 @@ object Prima::Application( Prima::Widget)
method Handle get_hint_widget();
method Rect get_indents() => apc_application_get_indents;
static Font get_message_font( char * dummy = "");
method SV * get_monitor_rects();
method Handle get_modal_window( int modalFlag = mtExclusive, Bool topMost = true);
method Point get_scroll_rate();
static SV * get_system_info( char * dummy = "");
Expand Down
13 changes: 13 additions & 0 deletions Makefile.PL
Expand Up @@ -1298,10 +1298,23 @@ EOF
}
}
}

if ( have_header( "X11/extensions/Xrandr.h")) {
print "Checking for presence of libXrandr... ";
if ( defined find_lib( 'Xrandr', '', '')) {
push @LIBS, 'Xrandr';
print "yes\n";
} else {
$DEFINES{HAVE_X11_EXTENSIONS_XRANDR_H} = undef;
print "no\n";
}
}

print "Using Xft library\n" if $cmd_options{WITH_XFT};
print "Using iconv library\n" if $cmd_options{WITH_ICONV};
print "Using gtk2 library\n" if $cmd_options{WITH_GTK2};
print "Using Xrandr library\n" if $DEFINES{HAVE_X11_EXTENSIONS_XRANDR_H};

}

sub generate_win32_def
Expand Down
5 changes: 5 additions & 0 deletions Prima/Application.pm
Expand Up @@ -542,6 +542,11 @@ if 0, the 'lowest' one ( in a simple case when window A is made modal
If a chain is empty C<undef> is returned. In case when a chain consists
of just one window, TOPMOST value is apparently irrelevant.
=item get_monitor_rects
Returns set of rects in format [X,Y,WIDTH,HEIGHT] identifying monitor
configurations. Currently works under X11 only.
=item get_scroll_rate
Returns two integer values of two system-specific
Expand Down
11 changes: 11 additions & 0 deletions include/apricot.h
Expand Up @@ -422,6 +422,14 @@ typedef struct { double re, im; } DComplex;
typedef struct { float r, ph; } TrigComplex;
typedef struct { double r, ph; } TrigDComplex;

typedef struct _Rect2
{
int x;
int y;
int width;
int height;
} Rect2, *PRect2;

#ifdef __cplusplus
#define nil NULL
#else
Expand Down Expand Up @@ -1938,6 +1946,9 @@ apc_application_get_os_info( char *system, int slen,
extern Point
apc_application_get_size( Handle self);

extern Rect2 *
apc_application_get_monitor_rects( Handle self, int * nrects);

extern Bool
apc_application_go( Handle self);

Expand Down
4 changes: 4 additions & 0 deletions include/unix/guts.h
Expand Up @@ -59,6 +59,9 @@
# define NEED_X11_EXTENSIONS_XRENDER_H
# endif
#endif
#ifdef HAVE_X11_EXTENSIONS_XRANDR_H
#include <X11/extensions/Xrandr.h>
#endif
#undef Font
#undef Drawable
#undef Bool
Expand Down Expand Up @@ -582,6 +585,7 @@ typedef struct _UnixGuts
Bool xft_disable_large_fonts;
int xft_xrender_major_opcode;
Bool xft_no_antialias;
Bool randr_extension;
struct MsgDlg *message_boxes;
XWindow grab_redirect;
Handle grab_widget;
Expand Down
5 changes: 4 additions & 1 deletion test/Object/Application.t
@@ -1,5 +1,5 @@
# $Id$
print "1..3 gp_init,pixel,forbidden actions\n";
print "1..4 gp_init,pixel,forbidden actions,monitor sizes\n";
my $a = $::application;

my @sz = $a-> size;
Expand All @@ -22,4 +22,7 @@ $a-> end_paint;
$a-> visible(0);
ok( $a-> visible && $a-> width == $sz[0] && $a-> height == $sz[1]);

my $msz = $a->get_monitor_rects;
ok( $msz && ref($msz) eq 'ARRAY' && @$msz > 0 );

1;
47 changes: 46 additions & 1 deletion unix/apc_app.c
Expand Up @@ -273,7 +273,14 @@ init_x11( char * error_buf )
guts. shared_image_extension = false;
guts. shared_image_completion_event = -1;
#endif

guts. randr_extension = false;
#ifdef HAVE_X11_EXTENSIONS_XRANDR_H
{
int dummy;
if ( XShapeQueryExtension( DISP, &dummy, &dummy))
guts. randr_extension = true;
}
#endif
XrmInitialize();
guts.db = get_database();
XrmStringToQuarkList( common_quarks, common_quarks_list);
Expand Down Expand Up @@ -848,6 +855,44 @@ apc_application_get_size( Handle self)
return guts. displaySize;
}

Rect2 *
apc_application_get_monitor_rects( Handle self, int * nrects)
{
#ifdef HAVE_X11_EXTENSIONS_XRANDR_H
XRRScreenResources * sr;
Rect2 * ret = nil;

if ( !guts. randr_extension) {
*nrects = 0;
return nil;
}

XCHECKPOINT;
sr = XRRGetScreenResources(DISP,guts.root);
if ( sr ) {
int i;
ret = malloc(sizeof(Rect2) * sr->ncrtc);
*nrects = sr->ncrtc;
for ( i = 0; i < sr->ncrtc; i++) {
XRRCrtcInfo * ci = XRRGetCrtcInfo (DISP, sr, sr->crtcs[i]);
ret[i].x = ci->x;
ret[i].y = guts.displaySize.y - ci->height - ci->y;
ret[i].width = ci->width;
ret[i].height = ci->height;
XRRFreeCrtcInfo(ci);
}
XRRFreeScreenResources(sr);
XCHECKPOINT;
} else {
*nrects = sr->ncrtc;
}
return ret;
#else
*nrects = 0;
return nil;
#endif
}

typedef struct {
int no;
void *sub;
Expand Down
7 changes: 7 additions & 0 deletions win32/apc.c
Expand Up @@ -364,6 +364,13 @@ apc_application_get_size( Handle self)
return ret;
}

Rect2 *
apc_application_get_monitor_rects( Handle self, int * nrects)
{
*nrects = 0;
return nil;
}

static Bool
files_rehash( Handle self, void * dummy)
{
Expand Down

0 comments on commit 918ab4f

Please sign in to comment.