commit 4392423694c90841681544faf1b45131b3c55701
parent 155c56d722426241382a79150bfbe606077c2cee
Author: anon <anon@example.com>
Date: Thu, 15 Oct 2026 04:17:23 +0000
Implement native window visibility and centering
Diffstat:
2 files changed, 206 insertions(+), 3 deletions(-)
diff --git a/decompiled/runtime/linux_window.c b/decompiled/runtime/linux_window.c
@@ -13,7 +13,7 @@ static struct window_class {
static struct {
struct window_class *class;
uint32_t handle, focus, style;
- int active;
+ int active, shown;
} client;
static uint32_t next_atom = 0xc000, next_handle = 0xf4000000u;
static struct display_context {
@@ -216,12 +216,18 @@ static void default_procedure(void)
break;
case 0x47: {
uint32_t position = MEM32(g_esp + 16), flags = MEM32(position + 24);
- if (!(flags & 2)) send_message(3, 0, (MEM32(position + 8) & 0xffffu) | (MEM32(position + 12) << 16));
- if (!(flags & 1)) send_message(5, 0, (MEM32(position + 16) & 0xffffu) | (MEM32(position + 20) << 16));
+ if ((flags & 0x40) && !client.shown) {
+ send_message(5, 0, (MEM32(position + 16) & 0xffffu) | (MEM32(position + 20) << 16));
+ send_message(3, 0, (MEM32(position + 8) & 0xffffu) | (MEM32(position + 12) << 16));
+ } else {
+ if (!(flags & 2)) send_message(3, 0, (MEM32(position + 8) & 0xffffu) | (MEM32(position + 12) << 16));
+ if (!(flags & 1)) send_message(5, 0, (MEM32(position + 16) & 0xffffu) | (MEM32(position + 20) << 16));
+ }
g_eax = 0;
break;
}
case 0x03: /* WM_MOVE */
+ case 0x18: /* WM_SHOWWINDOW; SDL applies visibility in ShowWindow. */
case 0x05: /* WM_SIZE */
case 0x7c: /* WM_STYLECHANGING */
case 0x7d: /* WM_STYLECHANGED */
@@ -248,6 +254,7 @@ static void release_window(void)
client.handle = 0;
client.focus = 0;
client.active = 0;
+ client.shown = 0;
client.class = NULL;
}
@@ -323,6 +330,59 @@ static void destroy_window(void)
g_esp += 8;
}
+static void show_window(void)
+{
+ uint32_t handle = MEM32(g_esp + 4), command = MEM32(g_esp + 8);
+ g_esp += 12;
+ g_eax = 0;
+ if (!client.handle || handle != client.handle) { MEM32(g_fs_base + 0x34) = 1400; return; }
+ /* The native process has no STARTF_USESHOWWINDOW override. */
+ if (command != 0 && command != 1 && command != 5 && command != 10) unsupported("show command", command);
+ int visible = !!(client.style & 0x10000000u), show = command != 0;
+ SDL_Window *window = linux_graphics_window();
+ if (visible == show) { g_eax = visible; return; }
+
+ /* Announce visibility before changing the guest style or native window. */
+ send_message(0x18, show, 0);
+ uint32_t record = guest_malloc(28);
+ if (!record) abort();
+ memset((void *)ADDR(record), 0, 28);
+ MEM32(record) = handle;
+ MEM32(record + 24) = show ? 0x43 : 0x83; /* SHOW/HIDE | NOMOVE | NOSIZE */
+ send_message(0x46, 0, record);
+ if (MEM32(record + 24) != (show ? 0x43u : 0x83u)) unsupported("show positioning flags", MEM32(record + 24));
+ if (show) {
+ client.style |= 0x10000000u;
+ SDL_ShowWindow(window);
+ SDL_RaiseWindow(window);
+ change_focus(handle);
+ } else {
+ client.style &= ~0x10000000u;
+ SDL_HideWindow(window);
+ }
+
+ /* SDL coordinates describe the client; the compositor owns nonclient paint. */
+ int x, y, width, height;
+ SDL_GetWindowPosition(window, &x, &y);
+ SDL_GetWindowSize(window, &width, &height);
+ MEM32(record + 8) = x; MEM32(record + 12) = y;
+ MEM32(record + 16) = width; MEM32(record + 20) = height;
+ MEM32(record + 24) |= 0x1804; /* NOZORDER | NOCLIENTMOVE | NOCLIENTSIZE */
+ send_message(0x47, 0, record);
+ guest_free(record);
+ if (show) client.shown = 1;
+ else {
+ if (client.active) {
+ client.active = 0;
+ send_message(0x86, 0, 0);
+ send_message(0x06, 0, 0);
+ send_message(0x1c, 0, 0);
+ }
+ change_focus(0);
+ }
+ g_eax = visible;
+}
+
static void system_parameters(void)
{
uint32_t action = MEM32(g_esp + 4), enabled = MEM32(g_esp + 8);
@@ -412,6 +472,58 @@ static void client_rect(void)
g_esp += 12;
}
+static void window_rect(void)
+{
+ uint32_t handle = MEM32(g_esp + 4), output = MEM32(g_esp + 8);
+ g_eax = 0;
+ if (!client.handle || handle != client.handle) MEM32(g_fs_base + 0x34) = 1400;
+ else {
+ /* Match MoveWindow/AdjustWindowRectEx's client-coordinate facade. */
+ int x, y, width, height;
+ SDL_GetWindowPosition(linux_graphics_window(), &x, &y);
+ SDL_GetWindowSize(linux_graphics_window(), &width, &height);
+ MEM32(output) = x; MEM32(output + 4) = y;
+ MEM32(output + 8) = x + width; MEM32(output + 12) = y + height;
+ g_eax = 1;
+ }
+ g_esp += 12;
+}
+
+static void set_window_position(void)
+{
+ uint32_t handle = MEM32(g_esp + 4), after = MEM32(g_esp + 8), flags = MEM32(g_esp + 28);
+ int x = MEM32(g_esp + 12), y = MEM32(g_esp + 16);
+ g_esp += 32;
+ g_eax = 0;
+ if (!client.handle || handle != client.handle) { MEM32(g_fs_base + 0x34) = 1400; return; }
+ if (after || flags != 5) unsupported("position flags/z-order", flags);
+
+ /* AO centers its shown window with NOSIZE | NOZORDER. */
+ uint32_t record = guest_malloc(28);
+ if (!record) abort();
+ memset((void *)ADDR(record), 0, 28);
+ MEM32(record) = handle;
+ MEM32(record + 8) = x; MEM32(record + 12) = y; MEM32(record + 24) = flags;
+ send_message(0x46, 0, record);
+ if (MEM32(record + 24) != 5) unsupported("position callback flags", MEM32(record + 24));
+ x = MEM32(record + 8); y = MEM32(record + 12);
+ SDL_Window *window = linux_graphics_window();
+ int old_x, old_y, width, height;
+ SDL_GetWindowPosition(window, &old_x, &old_y);
+ SDL_GetWindowSize(window, &width, &height);
+ SDL_SetWindowPosition(window, x, y);
+ change_focus(handle);
+ SDL_GetWindowPosition(window, &x, &y);
+ if (x != old_x || y != old_y) {
+ MEM32(record + 8) = x; MEM32(record + 12) = y;
+ MEM32(record + 16) = width; MEM32(record + 20) = height;
+ MEM32(record + 24) = 0x805; /* NOSIZE | NOZORDER | NOCLIENTSIZE */
+ send_message(0x47, 0, record);
+ }
+ guest_free(record);
+ g_eax = 1;
+}
+
static void move_window(void)
{
uint32_t handle = MEM32(g_esp + 4);
@@ -547,6 +659,7 @@ recomp_func_t linux_window_lookup(const char *dll, const char *name)
if (!strcmp(name, "CreateWindowExW")) return create_window_w;
if (!strcmp(name, "DefWindowProcA") || !strcmp(name, "DefWindowProcW")) return default_procedure;
if (!strcmp(name, "DestroyWindow")) return destroy_window;
+ if (!strcmp(name, "ShowWindow")) return show_window;
if (!strcmp(name, "SetFocus")) return set_focus;
if (!strcmp(name, "GetFocus")) return get_focus;
if (!strcmp(name, "SetWindowLongA") || !strcmp(name, "SetWindowLongW")) return set_window_long;
@@ -554,7 +667,9 @@ recomp_func_t linux_window_lookup(const char *dll, const char *name)
if (!strcmp(name, "AdjustWindowRectEx")) return adjust_window_rect;
if (!strcmp(name, "GetSystemMetrics")) return system_metrics;
if (!strcmp(name, "MoveWindow")) return move_window;
+ if (!strcmp(name, "SetWindowPos")) return set_window_position;
if (!strcmp(name, "GetClientRect")) return client_rect;
+ if (!strcmp(name, "GetWindowRect")) return window_rect;
if (!strcmp(name, "ClientToScreen")) return client_to_screen;
if (!strcmp(name, "GetDesktopWindow")) return desktop_window;
if (!strcmp(name, "GetDC")) return get_dc;
diff --git a/decompiled/tests/window.c b/decompiled/tests/window.c
@@ -22,6 +22,7 @@ static uint32_t instance, callback, atom, args[12], messages[32], message_count,
static int wide;
static int capture_focus, clear_in_callback;
static int capture_geometry;
+static int capture_visibility;
static uint32_t workspace(void)
{
@@ -57,6 +58,7 @@ static uint32_t call(const char *name, unsigned count, const uint32_t *arguments
if (count == 3) return ((uint32_t (WINAPI *)(uint32_t, uint32_t, uint32_t))function)(arguments[0], arguments[1], arguments[2]);
if (count == 4) return ((uint32_t (WINAPI *)(uint32_t, uint32_t, uint32_t, uint32_t))function)(arguments[0], arguments[1], arguments[2], arguments[3]);
if (count == 6) return ((uint32_t (WINAPI *)(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t))function)(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
+ if (count == 7) return ((uint32_t (WINAPI *)(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t))function)(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6]);
assert(count == 12);
return ((uint32_t (WINAPI *)(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t,
uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t))function)(
@@ -102,6 +104,7 @@ static uint32_t receive(uint32_t handle, uint32_t message, uint32_t wparam, uint
{
if (message == 0x24 || message == 0x81 || message == 0x83 ||
message == 1 || message == 2 || message == 0x82 ||
+ (capture_visibility && (message == 0x18 || message == 0x46 || message == 0x47 || message == 3 || message == 5)) ||
(capture_geometry && (message == 0x7c || message == 0x7d || message == 0x46 || message == 0x47 || message == 3 || message == 5)) ||
(capture_focus && (message == 0x46 || message == 0x1c || message == 0x86 ||
message == 6 || message == 7 || message == 8))) {
@@ -113,6 +116,10 @@ static uint32_t receive(uint32_t handle, uint32_t message, uint32_t wparam, uint
assert(memory(lparam)[0] == 0x04c00000u);
assert(memory(lparam)[1] == (message == 0x7c ? 0x00ca0000u : 0x04ca0000u));
}
+ if (capture_visibility && message == 0x18) {
+ uint32_t query[] = {handle, 0xfffffff0u};
+ assert(!lparam && !!(call("GetWindowLongA", 2, query) & 0x10000000u) != !!wparam);
+ }
if (capture_geometry && message == 5) {
assert(!wparam && lparam == 0x01e00280u);
uint32_t query[] = {handle, workspace() + 256};
@@ -268,6 +275,77 @@ static void focus_activation_and_reentrant_callbacks(void)
capture_focus = 0;
}
+static void visibility_dispatches_callbacks_and_preserves_geometry(void)
+{
+ uint32_t window = call("CreateWindowExA", 12, args);
+ assert(window);
+ call("SetFocus", 1, &window);
+ uint32_t show[] = {window, 10}, query[] = {window, workspace() + 256};
+ assert(call("GetClientRect", 2, query));
+ uint32_t original[4];
+ memcpy(original, memory(query[1]), sizeof(original));
+ capture_visibility = 1;
+ message_count = 0;
+
+ uint32_t previous = call("ShowWindow", 2, show);
+
+ const uint32_t first[] = {0x18, 0x46, 0x47, 5, 3};
+ assert(!previous && message_count == 5 && !memcmp(messages, first, sizeof(first)));
+ assert(call("GetClientRect", 2, query) && !memcmp(original, memory(query[1]), sizeof(original)));
+ uint32_t style[] = {window, 0xfffffff0u};
+ assert(call("GetWindowLongA", 2, style) & 0x10000000u);
+#ifndef _WIN32
+ assert(!(SDL_GetWindowFlags(linux_graphics_window()) & SDL_WINDOW_HIDDEN));
+#endif
+ message_count = 0;
+ show[1] = 5;
+ assert(call("ShowWindow", 2, show) && !message_count);
+ assert(call("GetWindowRect", 2, query));
+ uint32_t position[] = {window, 0, memory(query[1])[0] + 40, memory(query[1])[1] + 30, 0, 0, 5};
+ assert(call("SetWindowPos", 7, position));
+ const uint32_t moved[] = {0x46, 0x47, 3};
+ assert(message_count == 3 && !memcmp(messages, moved, sizeof(moved)));
+ assert(call("GetClientRect", 2, query) && !memcmp(original, memory(query[1]), sizeof(original)));
+ assert(call("GetWindowRect", 2, query));
+#ifdef _WIN32
+ assert(memory(query[1])[0] == position[2] && memory(query[1])[1] == position[3]);
+#endif
+ position[2] = memory(query[1])[0]; position[3] = memory(query[1])[1];
+ message_count = 0;
+ assert(call("SetWindowPos", 7, position));
+ assert(message_count == 1 && messages[0] == 0x46);
+ message_count = 0;
+ show[1] = 0;
+ assert(call("ShowWindow", 2, show));
+ const uint32_t changed[] = {0x18, 0x46, 0x47};
+ assert(message_count == 3 && !memcmp(messages, changed, sizeof(changed)));
+ assert(!(call("GetWindowLongA", 2, style) & 0x10000000u));
+ assert(!call("GetFocus", 0, NULL));
+#ifndef _WIN32
+ assert(SDL_GetWindowFlags(linux_graphics_window()) & SDL_WINDOW_HIDDEN);
+#endif
+ message_count = 0;
+ assert(!call("ShowWindow", 2, show) && !message_count);
+ show[1] = 1;
+ assert(!call("ShowWindow", 2, show));
+ const uint32_t restored[] = {0x18, 0x46, 0x46, 0x47};
+ /* The Windows desktop may deny foreground activation on a repeated show. */
+ assert((message_count == 3 && !memcmp(messages, changed, sizeof(changed))) ||
+ (message_count == 4 && !memcmp(messages, restored, sizeof(restored))));
+#ifndef _WIN32
+ assert(call("GetFocus", 0, NULL) == window);
+#endif
+ capture_visibility = 0;
+ show[1] = 0;
+ assert(call("ShowWindow", 2, show));
+ assert(call("DestroyWindow", 1, &window));
+ assert(!call("ShowWindow", 2, show) && error() == 1400);
+ memset(memory(query[1]), 0xa5, 20);
+ assert(!call("GetWindowRect", 2, query) && error() == 1400);
+ assert(!call("SetWindowPos", 7, position) && error() == 1400);
+ for (unsigned i = 0; i < 5; ++i) assert(memory(query[1])[i] == 0xa5a5a5a5);
+}
+
static void window_geometry_preserves_requested_client_area(void)
{
uint32_t window = call("CreateWindowExA", 12, args);
@@ -295,6 +373,14 @@ static void window_geometry_preserves_requested_client_area(void)
assert(memory(rectangle)[2] == 640 && memory(rectangle)[3] == 480);
static const uint32_t expected[] = {0x7c, 0x7d, 0x46, 0x24, 0x83, 0x47, 3, 5};
assert(message_count == 8 && !memcmp(messages, expected, sizeof(expected)));
+ memory(rectangle)[4] = 0xa5a5a5a5;
+ assert(call("GetWindowRect", 2, query));
+ uint32_t window_x = memory(rectangle)[0], window_y = memory(rectangle)[1];
+#ifdef _WIN32
+ assert(window_x == 20 && window_y == 30);
+#endif
+ assert(memory(rectangle)[2] == window_x + move[3] && memory(rectangle)[3] == window_y + move[4]);
+ assert(memory(rectangle)[4] == 0xa5a5a5a5);
memory(rectangle)[0] = 0; memory(rectangle)[1] = 0;
assert(call("ClientToScreen", 2, query));
uint32_t origin_x = memory(rectangle)[0], origin_y = memory(rectangle)[1];
@@ -313,6 +399,7 @@ static void window_geometry_preserves_requested_client_area(void)
int x, y;
SDL_GetWindowPosition(linux_graphics_window(), &x, &y);
assert(origin_x == (uint32_t)x && origin_y == (uint32_t)y);
+ assert(window_x == origin_x && window_y == origin_y);
#endif
capture_geometry = 0;
assert(call("DestroyWindow", 1, &window));
@@ -399,6 +486,7 @@ int main(void)
rejected_creation_releases_the_window();
focus_activation_and_reentrant_callbacks();
window_geometry_preserves_requested_client_area();
+ visibility_dispatches_callbacks_and_preserves_geometry();
class_release_invalidates_its_atom();
}
wide = 0;