Skip to content

Commit 7fdb067

Browse files
committed
Fix #18 and position the candidate window correctly in multi-monitor environments.
1 parent 6beef56 commit 7fdb067

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

ImeWindow.cpp

+12-16
Original file line numberDiff line numberDiff line change
@@ -66,30 +66,26 @@ void ImeWindow::onMouseMove(WPARAM wp, LPARAM lp) {
6666
void ImeWindow::move(int x, int y) {
6767
int w, h;
6868
size(&w, &h);
69-
70-
RECT rc;
71-
workingArea( &rc, hwnd_);
72-
if( x < rc.left )
69+
// ensure that the window does not fall outside of the screen.
70+
RECT rc = {x, y, x + w, y + h}; // current window rect
71+
// get the nearest monitor
72+
HMONITOR monitor = ::MonitorFromRect(&rc, MONITOR_DEFAULTTONEAREST);
73+
MONITORINFO mi;
74+
mi.cbSize = sizeof(mi);
75+
if(GetMonitorInfo(monitor, &mi))
76+
rc = mi.rcWork;
77+
if(x < rc.left)
7378
x = rc.left;
74-
else if( (x + w) > rc.right )
79+
else if((x + w) > rc.right)
7580
x = rc.right - w;
7681

77-
if( y < rc.top )
82+
if(y < rc.top)
7883
y = rc.top;
79-
else if( (y + h) > rc.bottom )
84+
else if((y + h) > rc.bottom)
8085
y = rc.bottom - h;
8186
::MoveWindow(hwnd_, x, y, w, h, TRUE);
8287
}
8388

84-
bool ImeWindow::workingArea(RECT* rc, HWND app_wnd) {
85-
HMONITOR mon = MonitorFromWindow( app_wnd, MONITOR_DEFAULTTONEAREST);
86-
MONITORINFO mi;
87-
mi.cbSize = sizeof(mi);
88-
if( GetMonitorInfo(mon, &mi) )
89-
*rc = mi.rcWork;
90-
return true;
91-
}
92-
9389
void ImeWindow::setFont(HFONT f) {
9490
if(font_)
9591
::DeleteObject(font_);

ImeWindow.h

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class ImeWindow: public Window {
3838
return textService_->isImmersive();
3939
}
4040

41-
static bool workingArea(RECT* rc, HWND app_wnd);
4241
void setFont(HFONT f);
4342
virtual void recalculateSize();
4443

0 commit comments

Comments
 (0)