From 4df745f07a4fb7fa7136763be313779df2a26255 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Sun, 15 Sep 2013 20:13:06 +0200 Subject: [PATCH] WinBoard multi-monitor support A patch provided by Tim Kosse --- winboard/winboard.c | 41 ++++++++++++++++++++++++++++++++++------- winboard/winboard.h | 6 ++++-- winboard/wlayout.c | 12 ++++++------ 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/winboard/winboard.c b/winboard/winboard.c index f86bdea..a24c8e4 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -224,6 +224,7 @@ static struct { int x; int y; int mode; } backTextureSquareInfo[BOARD_RANKS][BOA #else + #if defined(_winmajor) #define oldDialog (_winmajor < 4) #else @@ -982,16 +983,17 @@ InitApplication(HINSTANCE hInstance) /* Set by InitInstance, used by EnsureOnScreen */ int screenHeight, screenWidth; +RECT screenGeometry; void EnsureOnScreen(int *x, int *y, int minX, int minY) { // int gap = GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYCAPTION); /* Be sure window at (x,y) is not off screen (or even mostly off screen) */ - if (*x > screenWidth - 32) *x = 0; - if (*y > screenHeight - 32) *y = 0; - if (*x < minX) *x = minX; - if (*y < minY) *y = minY; + if (*x > screenGeometry.right - 32) *x = screenGeometry.left; + if (*y > screenGeometry.bottom - 32) *y = screenGeometry.top; + if (*x < screenGeometry.left + minX) *x = screenGeometry.left + minX; + if (*y < screenGeometry.top + minY) *y = screenGeometry.top + minY; } VOID @@ -1052,6 +1054,32 @@ InitTextures() } } +#ifndef SM_CXVIRTUALSCREEN +#define SM_CXVIRTUALSCREEN 78 +#endif +#ifndef SM_CYVIRTUALSCREEN +#define SM_CYVIRTUALSCREEN 79 +#endif +#ifndef SM_XVIRTUALSCREEN +#define SM_XVIRTUALSCREEN 76 +#endif +#ifndef SM_YVIRTUALSCREEN +#define SM_YVIRTUALSCREEN 77 +#endif + +VOID +InitGeometry() +{ + screenHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN); + if( !screenHeight ) screenHeight = GetSystemMetrics(SM_CYSCREEN); + screenWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN); + if( !screenWidth ) screenWidth = GetSystemMetrics(SM_CXSCREEN); + screenGeometry.left = GetSystemMetrics(SM_XVIRTUALSCREEN); + screenGeometry.top = GetSystemMetrics(SM_YVIRTUALSCREEN); + screenGeometry.right = screenGeometry.left + screenWidth; + screenGeometry.bottom = screenGeometry.top + screenHeight; +} + BOOL InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine) { @@ -1070,7 +1098,7 @@ InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine) GetCurrentDirectory(MSG_SIZ, installDir); } gameInfo.boardWidth = gameInfo.boardHeight = 8; // [HGM] won't have open window otherwise - screenWidth = screenHeight = 1000; // [HGM] placement: kludge to allow calling EnsureOnScreen from InitAppData + InitGeometry(); InitAppData(lpCmdLine); /* Get run-time parameters */ /* xboard, and older WinBoards, controlled the move sound with the appData.ringBellAfterMoves option. In the current WinBoard, we @@ -1117,8 +1145,7 @@ InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine) iconBlack = LoadIcon(hInstance, "icon_black"); iconCurrent = iconWhite; InitDrawingColors(); - screenHeight = GetSystemMetrics(SM_CYSCREEN); - screenWidth = GetSystemMetrics(SM_CXSCREEN); + InitPosition(0); // to set nr of ranks and files, which might be non-default through command-line args for (ibs = (int) NUM_SIZES - 1; ibs >= 0; ibs--) { /* Compute window size for each board size, and use the largest diff --git a/winboard/winboard.h b/winboard/winboard.h index b3eee24..e8dc9f4 100644 --- a/winboard/winboard.h +++ b/winboard/winboard.h @@ -194,7 +194,7 @@ typedef enum { extern WindowPlacement placementTab[NUM_WINDOWS]; extern HWND hwndTab[NUM_WINDOWS]; // this remains pure front-end. -void Translate( HWND hDlg, int id); +void Translate( HWND hDlg, int id); VOID InitWindowPlacement( WindowPlacement * wp ); VOID RestoreWindowPlacement( HWND hWnd, WindowPlacement * wp ); VOID ReattachAfterMove( LPRECT lprcOldPos, int new_x, int new_y, HWND hWndChild, WindowPlacement * pwpChild ); @@ -216,4 +216,6 @@ extern HWND gameListDialog; VOID EditTagsProc(void); extern HWND editTagsDialog; -extern int screenWidth, screenHeight; +extern int screenWidth, screenHeight; +extern RECT screenGeometry; // Top-left coordiate of the screen can be different from (0,0) + diff --git a/winboard/wlayout.c b/winboard/wlayout.c index 08f461f..0e9246e 100644 --- a/winboard/wlayout.c +++ b/winboard/wlayout.c @@ -173,15 +173,15 @@ VOID ReattachAfterSize( LPRECT lprcOldPos, int new_w, int new_h, HWND hWndChild, /* Adjust size & placement */ if(pwpChild->x + pwpChild->width >= lprcOldPos->right && - (pwpChild->x + pwpChild->width < screenWidth - 5 || delta_x > 0) ) // keep right edge glued to display edge if touching + (pwpChild->x + pwpChild->width < screenGeometry.right - 5 || delta_x > 0) ) // keep right edge glued to display edge if touching pwpChild->width += delta_x; - if(pwpChild->x + pwpChild->width >= screenWidth ) // don't move right edge off screen - pwpChild->width = screenWidth - pwpChild->x; + if(pwpChild->x + pwpChild->width >= screenGeometry.right ) // don't move right edge off screen + pwpChild->width = screenGeometry.right - pwpChild->x; if(pwpChild->y + pwpChild->height >= lprcOldPos->bottom && - (pwpChild->y + pwpChild->height < screenHeight - 35 || delta_y > 0) ) // keep bottom edge glued to display edge if touching + (pwpChild->y + pwpChild->height < screenGeometry.bottom - 35 || delta_y > 0) ) // keep bottom edge glued to display edge if touching pwpChild->height += delta_y; - if(pwpChild->y + pwpChild->height >= screenHeight - 30 ) // don't move bottom edge off screen - pwpChild->height = screenHeight - 30 - pwpChild->y; + if(pwpChild->y + pwpChild->height >= screenGeometry.bottom - 30 ) // don't move bottom edge off screen + pwpChild->height = screenGeometry.bottom - 30 - pwpChild->y; if(pwpChild->x >= lprcOldPos->right) pwpChild->width -= delta_x, pwpChild->x += delta_x; if(pwpChild->y >= lprcOldPos->bottom) pwpChild->height -= delta_y, pwpChild->y += delta_y; if(pwpChild->width < 30) pwpChild->width = 30; // force minimum width -- 1.7.0.4