Skip to content

Commit

Permalink
Implement window activate function
Browse files Browse the repository at this point in the history
  • Loading branch information
dapetcu21 committed Nov 21, 2019
1 parent 622dbc8 commit 2c265b0
Show file tree
Hide file tree
Showing 9 changed files with 290 additions and 81 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ defos.minimize()

---

**Activate (focus) window**. Not supported on HTML5.

```lua
defos.activate()
```

---

**Get/set the window's size and position** in screen coordinates. The window area
includes the title bar, so the actual contained game view area might be smaller
than the given metrics.
Expand Down
7 changes: 7 additions & 0 deletions defos/src/defos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ static int minimize(lua_State *L)
return 0;
}

static int activate(lua_State *L)
{
defos_activate();
return 0;
}

static int set_window_icon(lua_State *L)
{
const char *icon_path = luaL_checkstring(L, 1);
Expand Down Expand Up @@ -615,6 +621,7 @@ static const luaL_reg Module_methods[] =
{"set_maximized", set_maximized},
{"is_maximized", is_maximized},
{"minimize", minimize},
{"activate", activate},
{"set_console_visible", set_console_visible},
{"is_console_visible", is_console_visible},
{"set_cursor_visible", set_cursor_visible},
Expand Down
4 changes: 4 additions & 0 deletions defos/src/defos_html5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ void defos_minimize() {
dmLogWarning("Method 'minimize' is not supported in HTML5");
}

void defos_activate() {
dmLogWarning("Method 'activate' is not supported in HTML5");
}

void defos_toggle_fullscreen() {
EM_ASM(Module.toggleFullscreen(););
}
Expand Down
13 changes: 13 additions & 0 deletions defos/src/defos_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,19 @@ void defos_minimize()
XIconifyWindow(disp, win, screen);
}

void defos_activate()
{
send_message(win,
_NET_ACTIVE_WINDOW,
1,
1,
0,
0,
0
);
XFlush(disp);
}

void defos_set_console_visible(bool visible)
{
dmLogWarning("Method 'set_console_visible' is only supported on Windows");
Expand Down
4 changes: 4 additions & 0 deletions defos/src/defos_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ void defos_minimize() {
[window performMiniaturize: nil];
}

void defos_activate() {
[[NSApplication sharedApplication] activateIgnoringOtherApps: YES];
}

void defos_set_window_title(const char* title_lua) {
NSString* title = [NSString stringWithUTF8String:title_lua];
[window setTitle:title];
Expand Down
1 change: 1 addition & 0 deletions defos/src/defos_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ extern bool defos_is_fullscreen();
extern bool defos_is_maximized();
extern bool defos_is_always_on_top();
extern void defos_minimize();
extern void defos_activate();

extern void defos_set_window_title(const char* title_lua);
extern void defos_set_window_icon(const char *icon_path);
Expand Down
6 changes: 6 additions & 0 deletions defos/src/defos_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ void defos_minimize()
ShowWindow(window, SW_MINIMIZE);
}

void defos_activate()
{
HWND window = dmGraphics::GetNativeWindowsHWND();
SetForegroundWindow(window);
}

void defos_set_console_visible(bool visible)
{
::ShowWindow(::GetConsoleWindow(), visible ? SW_SHOW : SW_HIDE);
Expand Down
Loading

0 comments on commit 2c265b0

Please sign in to comment.