diff options
-rw-r--r-- | src/app.c | 6 | ||||
-rw-r--r-- | src/ui/window.c | 32 | ||||
-rw-r--r-- | src/win32.c | 24 |
3 files changed, 32 insertions, 30 deletions
@@ -190,11 +190,11 @@ static iString *serializePrefs_App_(const iApp *d) { | |||
190 | a moment to animate to its maximized size. */ | 190 | a moment to animate to its maximized size. */ |
191 | #if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) | 191 | #if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) |
192 | if (snap_MainWindow(d->window)) { | 192 | if (snap_MainWindow(d->window)) { |
193 | if (~SDL_GetWindowFlags(d->window->win) & SDL_WINDOW_MINIMIZED) { | 193 | if (~SDL_GetWindowFlags(d->window->base.win) & SDL_WINDOW_MINIMIZED) { |
194 | /* Save the actual visible window position, too, because snapped windows may | 194 | /* Save the actual visible window position, too, because snapped windows may |
195 | still be resized/moved without affecting normalRect. */ | 195 | still be resized/moved without affecting normalRect. */ |
196 | SDL_GetWindowPosition(d->window->win, &x, &y); | 196 | SDL_GetWindowPosition(d->window->base.win, &x, &y); |
197 | SDL_GetWindowSize(d->window->win, &w, &h); | 197 | SDL_GetWindowSize(d->window->base.win, &w, &h); |
198 | appendFormat_String( | 198 | appendFormat_String( |
199 | str, "~window.setrect snap:%d width:%d height:%d coord:%d %d\n", | 199 | str, "~window.setrect snap:%d width:%d height:%d coord:%d %d\n", |
200 | snap_MainWindow(d->window), w, h, x, y); | 200 | snap_MainWindow(d->window), w, h, x, y); |
diff --git a/src/ui/window.c b/src/ui/window.c index bc92f111..fb55bb52 100644 --- a/src/ui/window.c +++ b/src/ui/window.c | |||
@@ -318,12 +318,12 @@ static iRoot *rootAt_Window_(const iWindow *d, iInt2 coord) { | |||
318 | 318 | ||
319 | #if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) | 319 | #if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) |
320 | static SDL_HitTestResult hitTest_MainWindow_(SDL_Window *win, const SDL_Point *pos, void *data) { | 320 | static SDL_HitTestResult hitTest_MainWindow_(SDL_Window *win, const SDL_Point *pos, void *data) { |
321 | iWindow *d = data; | 321 | iMainWindow *d = data; |
322 | iAssert(d->win == win); | 322 | iAssert(d->base.win == win); |
323 | if (SDL_GetWindowFlags(d->win) & (SDL_WINDOW_MOUSE_CAPTURE | SDL_WINDOW_FULLSCREEN_DESKTOP)) { | 323 | if (SDL_GetWindowFlags(win) & (SDL_WINDOW_MOUSE_CAPTURE | SDL_WINDOW_FULLSCREEN_DESKTOP)) { |
324 | return SDL_HITTEST_NORMAL; | 324 | return SDL_HITTEST_NORMAL; |
325 | } | 325 | } |
326 | const int snap = snap_Window(d); | 326 | const int snap = snap_MainWindow(d); |
327 | int w, h; | 327 | int w, h; |
328 | SDL_GetWindowSize(win, &w, &h); | 328 | SDL_GetWindowSize(win, &w, &h); |
329 | /* TODO: Check if inside the caption label widget. */ | 329 | /* TODO: Check if inside the caption label widget. */ |
@@ -333,7 +333,7 @@ static SDL_HitTestResult hitTest_MainWindow_(SDL_Window *win, const SDL_Point *p | |||
333 | const iBool isBottom = pos->y >= h - gap_UI && snap != yMaximized_WindowSnap; | 333 | const iBool isBottom = pos->y >= h - gap_UI && snap != yMaximized_WindowSnap; |
334 | const int captionHeight = lineHeight_Text(uiContent_FontId) + gap_UI * 2; | 334 | const int captionHeight = lineHeight_Text(uiContent_FontId) + gap_UI * 2; |
335 | const int rightEdge = left_Rect(bounds_Widget(findChild_Widget( | 335 | const int rightEdge = left_Rect(bounds_Widget(findChild_Widget( |
336 | rootAt_Window_(d, init_I2(pos->x, pos->y))->widget, | 336 | rootAt_Window_(as_Window(d), init_I2(pos->x, pos->y))->widget, |
337 | "winbar.min"))); | 337 | "winbar.min"))); |
338 | d->place.lastHit = SDL_HITTEST_NORMAL; | 338 | d->place.lastHit = SDL_HITTEST_NORMAL; |
339 | if (snap != maximized_WindowSnap) { | 339 | if (snap != maximized_WindowSnap) { |
@@ -364,8 +364,8 @@ static SDL_HitTestResult hitTest_MainWindow_(SDL_Window *win, const SDL_Point *p | |||
364 | return SDL_HITTEST_NORMAL; | 364 | return SDL_HITTEST_NORMAL; |
365 | } | 365 | } |
366 | 366 | ||
367 | SDL_HitTestResult hitTest_Window(const iWindow *d, iInt2 pos) { | 367 | SDL_HitTestResult hitTest_MainWindow(const iMainWindow *d, iInt2 pos) { |
368 | return hitTest_Window_(d->win, &(SDL_Point){ pos.x, pos.y }, iConstCast(void *, d)); | 368 | return hitTest_MainWindow_(d->base.win, &(SDL_Point){ pos.x, pos.y }, iConstCast(void *, d)); |
369 | } | 369 | } |
370 | #endif | 370 | #endif |
371 | 371 | ||
@@ -387,7 +387,7 @@ iBool create_Window_(iWindow *d, iRect rect, uint32_t flags) { | |||
387 | #if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) | 387 | #if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) |
388 | if (type_Window(d) == main_WindowType && prefs_App()->customFrame) { | 388 | if (type_Window(d) == main_WindowType && prefs_App()->customFrame) { |
389 | /* Register a handler for window hit testing (drag, resize). */ | 389 | /* Register a handler for window hit testing (drag, resize). */ |
390 | SDL_SetWindowHitTest(d->win, hitTest_Window_, d); | 390 | SDL_SetWindowHitTest(d->win, hitTest_MainWindow_, d); |
391 | SDL_SetWindowResizable(d->win, SDL_TRUE); | 391 | SDL_SetWindowResizable(d->win, SDL_TRUE); |
392 | } | 392 | } |
393 | #endif | 393 | #endif |
@@ -1453,8 +1453,8 @@ void setSplitMode_MainWindow(iMainWindow *d, int splitFlags) { | |||
1453 | postCommand_App("window.resized"); | 1453 | postCommand_App("window.resized"); |
1454 | #if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) | 1454 | #if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) |
1455 | /* Update custom frame controls. */{ | 1455 | /* Update custom frame controls. */{ |
1456 | const iBool hideCtl0 = numRoots_Window(d) != 1; | 1456 | const iBool hideCtl0 = numRoots_Window(as_Window(d)) != 1; |
1457 | iWidget *winBar = findChild_Widget(d->roots[0]->widget, "winbar"); | 1457 | iWidget *winBar = findChild_Widget(d->base.roots[0]->widget, "winbar"); |
1458 | if (winBar) { | 1458 | if (winBar) { |
1459 | setFlags_Widget( | 1459 | setFlags_Widget( |
1460 | findChild_Widget(winBar, "winbar.min"), hidden_WidgetFlag, hideCtl0); | 1460 | findChild_Widget(winBar, "winbar.min"), hidden_WidgetFlag, hideCtl0); |
@@ -1462,8 +1462,8 @@ void setSplitMode_MainWindow(iMainWindow *d, int splitFlags) { | |||
1462 | findChild_Widget(winBar, "winbar.max"), hidden_WidgetFlag, hideCtl0); | 1462 | findChild_Widget(winBar, "winbar.max"), hidden_WidgetFlag, hideCtl0); |
1463 | setFlags_Widget( | 1463 | setFlags_Widget( |
1464 | findChild_Widget(winBar, "winbar.close"), hidden_WidgetFlag, hideCtl0); | 1464 | findChild_Widget(winBar, "winbar.close"), hidden_WidgetFlag, hideCtl0); |
1465 | if (d->roots[1]) { | 1465 | if (d->base.roots[1]) { |
1466 | winBar = findChild_Widget(d->roots[1]->widget, "winbar"); | 1466 | winBar = findChild_Widget(d->base.roots[1]->widget, "winbar"); |
1467 | setFlags_Widget( | 1467 | setFlags_Widget( |
1468 | findChild_Widget(winBar, "winbar.icon"), hidden_WidgetFlag, iTrue); | 1468 | findChild_Widget(winBar, "winbar.icon"), hidden_WidgetFlag, iTrue); |
1469 | setFlags_Widget( | 1469 | setFlags_Widget( |
@@ -1548,8 +1548,8 @@ void setSnap_MainWindow(iMainWindow *d, int snapMode) { | |||
1548 | newRect.pos.y += newRect.size.y; | 1548 | newRect.pos.y += newRect.size.y; |
1549 | } | 1549 | } |
1550 | /* Update window controls. */ | 1550 | /* Update window controls. */ |
1551 | iForIndices(rootIndex, d->roots) { | 1551 | iForIndices(rootIndex, d->base.roots) { |
1552 | iRoot *root = d->roots[rootIndex]; | 1552 | iRoot *root = d->base.roots[rootIndex]; |
1553 | if (!root) continue; | 1553 | if (!root) continue; |
1554 | iWidget *winBar = findChild_Widget(root->widget, "winbar"); | 1554 | iWidget *winBar = findChild_Widget(root->widget, "winbar"); |
1555 | updateTextCStr_LabelWidget(findChild_Widget(winBar, "winbar.max"), | 1555 | updateTextCStr_LabelWidget(findChild_Widget(winBar, "winbar.max"), |
@@ -1558,8 +1558,8 @@ void setSnap_MainWindow(iMainWindow *d, int snapMode) { | |||
1558 | const iBool wasVisible = isVisible_Widget(winBar); | 1558 | const iBool wasVisible = isVisible_Widget(winBar); |
1559 | setFlags_Widget(winBar, hidden_WidgetFlag, d->place.snap == fullscreen_WindowSnap); | 1559 | setFlags_Widget(winBar, hidden_WidgetFlag, d->place.snap == fullscreen_WindowSnap); |
1560 | if (newRect.size.x) { | 1560 | if (newRect.size.x) { |
1561 | SDL_SetWindowPosition(d->win, newRect.pos.x, newRect.pos.y); | 1561 | SDL_SetWindowPosition(d->base.win, newRect.pos.x, newRect.pos.y); |
1562 | SDL_SetWindowSize(d->win, newRect.size.x, newRect.size.y); | 1562 | SDL_SetWindowSize(d->base.win, newRect.size.x, newRect.size.y); |
1563 | postCommand_App("window.resized"); | 1563 | postCommand_App("window.resized"); |
1564 | } | 1564 | } |
1565 | if (wasVisible != isVisible_Widget(winBar)) { | 1565 | if (wasVisible != isVisible_Widget(winBar)) { |
diff --git a/src/win32.c b/src/win32.c index d040d8a9..63e7885a 100644 --- a/src/win32.c +++ b/src/win32.c | |||
@@ -96,21 +96,22 @@ void processNativeEvent_Win32(const struct SDL_SysWMmsg *msg, iWindow *window) { | |||
96 | } | 96 | } |
97 | case WM_KEYUP: { | 97 | case WM_KEYUP: { |
98 | if (winDown_[0] || winDown_[1]) { | 98 | if (winDown_[0] || winDown_[1]) { |
99 | iMainWindow *mw = as_MainWindow(window); | ||
99 | /* Emulate the default window snapping behavior. */ | 100 | /* Emulate the default window snapping behavior. */ |
100 | int snap = snap_Window(window); | 101 | int snap = snap_MainWindow(mw); |
101 | if (wp == VK_LEFT) { | 102 | if (wp == VK_LEFT) { |
102 | snap &= ~(topBit_WindowSnap | bottomBit_WindowSnap); | 103 | snap &= ~(topBit_WindowSnap | bottomBit_WindowSnap); |
103 | setSnap_Window(window, | 104 | setSnap_MainWindow(mw, |
104 | snap == right_WindowSnap ? 0 : left_WindowSnap); | 105 | snap == right_WindowSnap ? 0 : left_WindowSnap); |
105 | } | 106 | } |
106 | else if (wp == VK_RIGHT) { | 107 | else if (wp == VK_RIGHT) { |
107 | snap &= ~(topBit_WindowSnap | bottomBit_WindowSnap); | 108 | snap &= ~(topBit_WindowSnap | bottomBit_WindowSnap); |
108 | setSnap_Window(window, | 109 | setSnap_MainWindow(mw, |
109 | snap == left_WindowSnap ? 0 : right_WindowSnap); | 110 | snap == left_WindowSnap ? 0 : right_WindowSnap); |
110 | } | 111 | } |
111 | else if (wp == VK_UP) { | 112 | else if (wp == VK_UP) { |
112 | if (~snap & topBit_WindowSnap) { | 113 | if (~snap & topBit_WindowSnap) { |
113 | setSnap_Window(window, | 114 | setSnap_MainWindow(mw, |
114 | snap & bottomBit_WindowSnap ? snap & ~bottomBit_WindowSnap | 115 | snap & bottomBit_WindowSnap ? snap & ~bottomBit_WindowSnap |
115 | : snap == left_WindowSnap || snap == right_WindowSnap | 116 | : snap == left_WindowSnap || snap == right_WindowSnap |
116 | ? snap | topBit_WindowSnap | 117 | ? snap | topBit_WindowSnap |
@@ -125,7 +126,7 @@ void processNativeEvent_Win32(const struct SDL_SysWMmsg *msg, iWindow *window) { | |||
125 | postCommand_App("window.minimize"); | 126 | postCommand_App("window.minimize"); |
126 | } | 127 | } |
127 | else { | 128 | else { |
128 | setSnap_Window(window, | 129 | setSnap_MainWindow(mw, |
129 | snap == maximized_WindowSnap ? 0 | 130 | snap == maximized_WindowSnap ? 0 |
130 | : snap & topBit_WindowSnap ? snap & ~topBit_WindowSnap | 131 | : snap & topBit_WindowSnap ? snap & ~topBit_WindowSnap |
131 | : snap == left_WindowSnap || snap == right_WindowSnap | 132 | : snap == left_WindowSnap || snap == right_WindowSnap |
@@ -143,20 +144,21 @@ void processNativeEvent_Win32(const struct SDL_SysWMmsg *msg, iWindow *window) { | |||
143 | break; | 144 | break; |
144 | } | 145 | } |
145 | case WM_NCLBUTTONDBLCLK: { | 146 | case WM_NCLBUTTONDBLCLK: { |
147 | iMainWindow *mw = as_MainWindow(window); | ||
146 | POINT point = { GET_X_LPARAM(msg->msg.win.lParam), | 148 | POINT point = { GET_X_LPARAM(msg->msg.win.lParam), |
147 | GET_Y_LPARAM(msg->msg.win.lParam) }; | 149 | GET_Y_LPARAM(msg->msg.win.lParam) }; |
148 | ScreenToClient(hwnd, &point); | 150 | ScreenToClient(hwnd, &point); |
149 | iInt2 pos = init_I2(point.x, point.y); | 151 | iInt2 pos = init_I2(point.x, point.y); |
150 | switch (hitTest_Window(window, pos)) { | 152 | switch (hitTest_MainWindow(mw, pos)) { |
151 | case SDL_HITTEST_DRAGGABLE: | 153 | case SDL_HITTEST_DRAGGABLE: |
152 | window->ignoreClick = iTrue; /* avoid hitting something inside the window */ | 154 | window->ignoreClick = iTrue; /* avoid hitting something inside the window */ |
153 | postCommandf_App("window.%s", | 155 | postCommandf_App("window.%s", |
154 | snap_Window(window) ? "restore" : "maximize toggle:1"); | 156 | snap_MainWindow(mw) ? "restore" : "maximize toggle:1"); |
155 | break; | 157 | break; |
156 | case SDL_HITTEST_RESIZE_TOP: | 158 | case SDL_HITTEST_RESIZE_TOP: |
157 | case SDL_HITTEST_RESIZE_BOTTOM: { | 159 | case SDL_HITTEST_RESIZE_BOTTOM: { |
158 | window->ignoreClick = iTrue; /* avoid hitting something inside the window */ | 160 | window->ignoreClick = iTrue; /* avoid hitting something inside the window */ |
159 | setSnap_Window(window, yMaximized_WindowSnap); | 161 | setSnap_MainWindow(mw, yMaximized_WindowSnap); |
160 | break; | 162 | break; |
161 | } | 163 | } |
162 | } | 164 | } |
@@ -170,7 +172,7 @@ void processNativeEvent_Win32(const struct SDL_SysWMmsg *msg, iWindow *window) { | |||
170 | printf("%d,%d\n", point.x, point.y); fflush(stdout); | 172 | printf("%d,%d\n", point.x, point.y); fflush(stdout); |
171 | ScreenToClient(hwnd, &point); | 173 | ScreenToClient(hwnd, &point); |
172 | iInt2 pos = init_I2(point.x, point.y); | 174 | iInt2 pos = init_I2(point.x, point.y); |
173 | if (hitTest_Window(window, pos) == SDL_HITTEST_DRAGGABLE) { | 175 | if (hitTest_MainWindow(as_MainWindow(window), pos) == SDL_HITTEST_DRAGGABLE) { |
174 | printf("released draggable\n"); fflush(stdout); | 176 | printf("released draggable\n"); fflush(stdout); |
175 | } | 177 | } |
176 | break; | 178 | break; |