Skip to content

Commit

Permalink
- better algorithm for centering windows in multi-monitor setup
Browse files Browse the repository at this point in the history
  • Loading branch information
dk committed Feb 18, 2014
1 parent 86a6614 commit 94d7fc1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
20 changes: 18 additions & 2 deletions Widget.c
Original file line number Diff line number Diff line change
Expand Up @@ -1819,8 +1819,24 @@ Widget_set_centered( Handle self, Bool x, Bool y)
Point size = CWidget( parent)-> get_size( parent);
Point mysize = my-> get_size ( self);
Point mypos = my-> get_origin( self);
if ( x) mypos. x = ( size. x - mysize. x) / 2;
if ( y) mypos. y = ( size. y - mysize. y) / 2;
Point delta = {0,0};
if ( parent == application ) {
int i, nrects = 0;
Rect2 *best = nil, *rects = apc_application_get_monitor_rects( application, &nrects);
for ( i = 0; i < nrects; i++) {
Rect2 * curr = rects + i;
if ( best == nil || best-> x > curr->x || best->y > curr->y)
best = curr;
}
if ( best ) {
delta.x = best->x;
delta.y = best->y;
size.x = best->width;
size.y = best->height;
}
}
if ( x) mypos. x = ( size. x - mysize. x) / 2 + delta.x;
if ( y) mypos. y = ( size. y - mysize. y) / 2 + delta.y;
my-> set_origin( self, mypos);
}

Expand Down
30 changes: 25 additions & 5 deletions unix/apc_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ apc_show_message( const char * message, Bool utf8)
{
char ** wrapped;
Font f;
Point appSz;
Point appSz, appPos;
Point textSz;
Point winSz;
TextWrapRec twr;
Expand All @@ -908,6 +908,26 @@ apc_show_message( const char * message, Bool utf8)
apc_widget_set_capture( guts. grab_widget, 0, 0);

appSz = apc_application_get_size( nilHandle);
appPos.x = 0;
appPos.y = 0;

/* multi-monitor centering */
{
int i, nrects = 0;
Rect2 *best = nil, *rects = apc_application_get_monitor_rects( application, &nrects);
for ( i = 0; i < nrects; i++) {
Rect2 * curr = rects + i;
if ( best == nil || best-> x > curr->x || best->y > curr->y)
best = curr;
}
if ( best ) {
appPos.x = best->x;
appPos.y = best->y;
appSz.x = best->width;
appSz.y = best->height;
}
}

/* acquiring message font and wrapping message text */
{
PCachedFont cf;
Expand Down Expand Up @@ -1031,7 +1051,7 @@ apc_show_message( const char * message, Bool utf8)
attrs. do_not_propagate_mask = attrs. event_mask;

md. w = XCreateWindow( DISP, guts. root,
( appSz.x - winSz.x) / 2, ( appSz.y - winSz.y) / 2,
appPos.x + ( appSz.x - winSz.x) / 2, appPos.y + ( appSz.y - winSz.y) / 2,
winSz.x, winSz.y, 0, CopyFromParent, InputOutput,
CopyFromParent, CWEventMask | CWOverrideRedirect, &attrs);
XCHECKPOINT;
Expand All @@ -1044,8 +1064,8 @@ apc_show_message( const char * message, Bool utf8)
xs. flags = PMinSize | PMaxSize | USPosition;
xs. min_width = xs. max_width = winSz.x;
xs. min_height = xs. max_height = winSz. y;
xs. x = ( appSz.x - winSz.x) / 2;
xs. y = ( appSz.y - winSz.y) / 2;
xs. x = appPos.x + ( appSz.x - winSz.x) / 2;
xs. y = appPos.y + ( appSz.y - winSz.y) / 2;
XSetWMNormalHints( DISP, md. w, &xs);
if ( XStringListToTextProperty( &prima, 1, &p) != 0) {
XSetWMIconName( DISP, md. w, &p);
Expand Down Expand Up @@ -1077,7 +1097,7 @@ apc_show_message( const char * message, Bool utf8)

XMapWindow( DISP, md. w);
XMoveResizeWindow( DISP, md. w,
( appSz.x - winSz.x) / 2, ( appSz.y - winSz.y) / 2, winSz.x, winSz.y);
appPos.x + ( appSz.x - winSz.x) / 2, appPos.y + ( appSz.y - winSz.y) / 2, winSz.x, winSz.y);
XNoOp( DISP);
XFlush( DISP);
while ( md. active && !guts. applicationClose)
Expand Down

0 comments on commit 94d7fc1

Please sign in to comment.