Skip to content

Commit

Permalink
Merge pull request #142 from paweljarosz/master
Browse files Browse the repository at this point in the history
Added Windows implementation for toggling window border
  • Loading branch information
AGulev authored Oct 5, 2024
2 parents 7ab2431 + eecb6fc commit 5ea480b
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 2,387 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ bool_value = defos.is_fullscreen()

---

**Toggle borderless window**. Works and tested only on Windows platform.

```lua
defos.set_borderless(bool_value)
defos.toggle_borderless()
bool_value = defos.is_borderless()
```

---

**Keep window on top**. Not supported on HTML5.

```lua
Expand Down
23 changes: 23 additions & 0 deletions defos/src/defos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,26 @@ static int is_fullscreen(lua_State *L)
return 1;
}

static int toggle_borderless(lua_State *L)
{
defos_toggle_borderless();
return 0;
}

static int set_borderless(lua_State *L)
{
if (checkboolean(L, 1) != defos_is_borderless()) {
defos_toggle_borderless();
}
return 0;
}

static int is_borderless(lua_State *L)
{
lua_pushboolean(L, defos_is_borderless());
return 1;
}

static int toggle_maximized(lua_State *L)
{
defos_toggle_maximized();
Expand Down Expand Up @@ -622,6 +642,9 @@ static const luaL_reg Module_methods[] =
{"toggle_fullscreen", toggle_fullscreen},
{"set_fullscreen", set_fullscreen},
{"is_fullscreen", is_fullscreen},
{"toggle_borderless", toggle_borderless},
{"set_borderless", set_borderless},
{"is_borderless", is_borderless},
{"toggle_always_on_top", toggle_always_on_top},
{"set_always_on_top", set_always_on_top},
{"is_always_on_top", is_always_on_top},
Expand Down
9 changes: 9 additions & 0 deletions defos/src/defos_html5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ void defos_toggle_fullscreen() {
EM_ASM(Module.toggleFullscreen(););
}

void defos_toggle_borderless() {
// TODO: add defos_toggle_borderless for HTML5
}

void defos_toggle_maximized() {
if (is_maximized) {
is_maximized = false;
Expand All @@ -166,6 +170,11 @@ bool defos_is_fullscreen() {
return is_fullscreen != 0;
}

bool defos_is_borderless() {
// TODO: add defos_is_borderless for HTML5
return true;
}

bool defos_is_maximized() {
return is_maximized;
}
Expand Down
9 changes: 9 additions & 0 deletions defos/src/defos_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ bool defos_is_fullscreen()
return hint_state_contains_atom(NET_WM_STATE_FULLSCREEN);
}

bool defos_is_borderless() {
// TODO: add defos_is_borderless for Linux
return true;
}

bool defos_is_maximized()
{
return hint_state_contains_atom(NET_WM_STATE_MAXIMIZED_VERT);
Expand Down Expand Up @@ -299,6 +304,10 @@ void defos_toggle_fullscreen()
XFlush(disp);
}

void defos_toggle_borderless() {
// TODO: add defos_toggle_borderless for Linux
}

void defos_toggle_maximized()
{
send_message(win,
Expand Down
9 changes: 9 additions & 0 deletions defos/src/defos_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ void defos_toggle_fullscreen() {
[window toggleFullScreen:window];
}

void defos_toggle_borderless() {
// TODO: add defos_toggle_borderless for Mac
}

void defos_toggle_maximized() {
if (defos_is_fullscreen()){
defos_toggle_fullscreen();
Expand All @@ -117,6 +121,11 @@ bool defos_is_fullscreen() {
return fullscreen == YES;
}

bool defos_is_borderless() {
// TODO: add defos_is_borderless for Mac
return true;
}

bool defos_is_maximized() {
return is_maximized;
}
Expand Down
2 changes: 2 additions & 0 deletions defos/src/defos_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ extern void defos_disable_minimize_button();
extern void defos_disable_window_resize();

extern void defos_toggle_fullscreen();
extern void defos_toggle_borderless();
extern void defos_toggle_maximized();
extern void defos_toggle_always_on_top();
extern bool defos_is_fullscreen();
extern bool defos_is_borderless();
extern bool defos_is_maximized();
extern bool defos_is_always_on_top();
extern void defos_minimize();
Expand Down
26 changes: 26 additions & 0 deletions defos/src/defos_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ bool defos_is_fullscreen()
return !(get_window_style() & WS_OVERLAPPEDWINDOW);
}

bool defos_is_borderless()
{
return !(get_window_style() & (WS_CAPTION | WS_THICKFRAME));
}

bool defos_is_maximized()
{
return !!IsZoomed(dmGraphics::GetNativeWindowsHWND());
Expand Down Expand Up @@ -153,6 +158,27 @@ void defos_toggle_fullscreen()
}
}

void defos_toggle_borderless()
{
LONG_PTR style = get_window_style();

if (!defos_is_borderless())
{
// Remove the WS_CAPTION and WS_THICKFRAME styles to make the window borderless
style &= ~(WS_CAPTION | WS_THICKFRAME);
}
else
{
// Restore the default window style with borders
style |= (WS_CAPTION | WS_THICKFRAME);
}
set_window_style(style);

// Adjust the window size and position to apply the new style without changing the window's position or size
HWND window = dmGraphics::GetNativeWindowsHWND();
SetWindowPos(window, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
}

void defos_toggle_maximized()
{
if (defos_is_fullscreen())
Expand Down
Loading

0 comments on commit 5ea480b

Please sign in to comment.