Skip to content

Borderless Mode (Windows) #1394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions desktop-ui/desktop-ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ auto nall::main(Arguments arguments) -> void {
print(" --terminal Create new terminal window\n");
#endif
print(" --fullscreen Start in full screen mode\n");
#if defined(PLATFORM_WINDOWS)
print(" --no/--Borderless Disable/Enable Borderless Window");
#endif
print(" --system name Specify the system name\n");
print(" --shader name Specify the name of the shader to use\n");
print(" --setting name=value Specify a value for a setting\n");
Expand All @@ -126,6 +129,15 @@ auto nall::main(Arguments arguments) -> void {
print("\n");
return;
}

#if defined(PLATFORM_WINDOWS)
if(arguments.take("--noBorderless")) {
settings.general.borderless = false;
}
if(arguments.take("--Borderless")) {
settings.general.borderless = true;
}
#endif

if(arguments.take("--dump-all-settings")) {
function<void(const Markup::Node&, string)> dump;
Expand Down
6 changes: 6 additions & 0 deletions desktop-ui/input/hotkeys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ auto InputManager::createHotkeys() -> void {
if(!emulator) return;
if(settings.audio.volume >= (f64)(0.1)) settings.audio.volume -= (f64)(0.1);
}));

#if defined(PLATFORM_WINDOWS)
hotkeys.append(InputHotkey("Toggle Borderless Window").onPress([&] {
program.updateBorderless();
}));
#endif
}

auto InputManager::pollHotkeys() -> void {
Expand Down
11 changes: 11 additions & 0 deletions desktop-ui/presentation/presentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ Presentation::Presentation() {
}
if(visible()) resizeWindow();
}).doToggle();
#if defined(PLATFORM_WINDOWS)
showBorderlessSetting.setText("Borderless Window").setChecked(settings.general.borderless).onToggle([&] {
settings.general.borderless = showBorderlessSetting.checked();
if(!showBorderlessSetting.checked()) {
Window::setBorderless(false);
}else{
Window::setBorderless(true);
}
if(visible()) resizeWindow();
}).doToggle();
#endif
videoSettingsAction.setText("Video" ELLIPSIS).setIcon(Icon::Device::Display).onActivate([&] {
settingsWindow.show("Video");
});
Expand Down
3 changes: 3 additions & 0 deletions desktop-ui/presentation/presentation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ struct Presentation : Window {
MenuSeparator groupSettingsSeparatpr{&settingsMenu};
MenuCheckItem muteAudioSetting{&settingsMenu};
MenuCheckItem showStatusBarSetting{&settingsMenu};
#if defined(PLATFORM_WINDOWS)
MenuCheckItem showBorderlessSetting{&settingsMenu};
#endif
MenuSeparator audioSettingsSeparator{&settingsMenu};
MenuItem videoSettingsAction{&settingsMenu};
MenuItem audioSettingsAction{&settingsMenu};
Expand Down
3 changes: 3 additions & 0 deletions desktop-ui/program/program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ struct Program : ares::Platform {
//status.cpp
auto updateMessage() -> void;
auto showMessage(const string&) -> void;
#if defined(PLATFORM_WINDOWS)
auto updateBorderless() -> void;
#endif

//utility.cpp
auto pause(bool) -> void;
Expand Down
14 changes: 14 additions & 0 deletions desktop-ui/program/status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,17 @@ auto Program::showMessage(const string& text) -> void {
messages.append({chrono::millisecond(), text});
printf("%s\n", (const char*)text);
}
#if defined(PLATFORM_WINDOWS)
auto Program::updateBorderless() -> void {
bool state = settings.general.borderless ? false : true;
if(!state){
presentation.Window::setBorderless(false);
presentation.showBorderlessSetting.setChecked(false);
} else {
presentation.Window::setBorderless(true);
presentation.showBorderlessSetting.setChecked(true);
}
settings.general.borderless = state;
if(presentation.visible()) presentation.resizeWindow();
}
#endif
3 changes: 3 additions & 0 deletions desktop-ui/settings/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ auto Settings::process(bool load) -> void {
bind(boolean, "General/RunAhead", general.runAhead);
bind(boolean, "General/AutoSaveMemory", general.autoSaveMemory);
bind(boolean, "General/HomebrewMode", general.homebrewMode);
#if defined(PLATFORM_WINDOWS)
bind(boolean, "General/Borderless", general.borderless);
#endif

bind(natural, "Rewind/Length", rewind.length);
bind(natural, "Rewind/Frequency", rewind.frequency);
Expand Down
3 changes: 3 additions & 0 deletions desktop-ui/settings/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ struct Settings : Markup::Node {
bool runAhead = false;
bool autoSaveMemory = true;
bool homebrewMode = false;
#if defined(PLATFORM_WINDOWS)
bool borderless = false;
#endif
} general;

struct Rewind {
Expand Down
2 changes: 2 additions & 0 deletions hiro/core/shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ struct Window : sWindow {
auto append(sSizable sizable) { return self().append(sizable), *this; }
auto append(sStatusBar statusBar) { return self().append(statusBar), *this; }
auto backgroundColor() const { return self().backgroundColor(); }
auto borderless() const { return self().borderless(); }
auto dismissable() const { return self().dismissable(); }
auto doClose() const { return self().doClose(); }
auto doDrop(vector<string> names) const { return self().doDrop(names); }
Expand Down Expand Up @@ -937,6 +938,7 @@ struct Window : sWindow {
auto setAlignment(Alignment alignment = Alignment::Center) { return self().setAlignment(alignment), *this; }
auto setAlignment(sWindow relativeTo, Alignment alignment = Alignment::Center) { return self().setAlignment(relativeTo, alignment), *this; }
auto setBackgroundColor(Color color = {}) { return self().setBackgroundColor(color), *this; }
auto setBorderless(bool borderless = true) { return self().setBorderless(borderless), *this; }
auto setDismissable(bool dismissable = true) { return self().setDismissable(dismissable), *this; }
auto setDroppable(bool droppable = true) { return self().setDroppable(droppable), *this; }
auto setFrameGeometry(Geometry geometry) { return self().setFrameGeometry(geometry), *this; }
Expand Down
10 changes: 10 additions & 0 deletions hiro/core/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,14 @@ auto mWindow::title() const -> string {
return state.title;
}

auto mWindow::borderless() const -> bool {
return state.borderless;
}

auto mWindow::setBorderless(bool borderless) -> type& {
state.borderless = borderless;
signal(setBorderless, borderless);
return *this;
}

#endif
5 changes: 4 additions & 1 deletion hiro/core/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct mWindow : mObject {
auto append(sSizable sizable) -> type&;
auto append(sStatusBar statusBar) -> type&;
auto backgroundColor() const -> Color;
auto borderless() const -> bool;
auto dismissable() const -> bool;
auto doClose() const -> void;
auto doDrop(vector<string>) const -> void;
Expand Down Expand Up @@ -42,6 +43,7 @@ struct mWindow : mObject {
auto setAlignment(Alignment = Alignment::Center) -> type&;
auto setAlignment(sWindow relativeTo, Alignment = Alignment::Center) -> type&;
auto setBackgroundColor(Color color = {}) -> type&;
auto setBorderless(bool borderless = true) -> type&;
auto setDismissable(bool dismissable = true) -> type&;
auto setDroppable(bool droppable = true) -> type&;
auto setFrameGeometry(Geometry geometry) -> type&;
Expand Down Expand Up @@ -69,7 +71,8 @@ struct mWindow : mObject {
//private:
struct State {
Color backgroundColor;
bool dismissable = false;
bool borderless = false;
bool dismissable = false;
bool droppable = false;
bool fullScreen = false;
Geometry geometry = {128, 128, 256, 256};
Expand Down
10 changes: 10 additions & 0 deletions hiro/windows/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ static auto CALLBACK Window_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARA
static constexpr u32 PopupStyle = WS_POPUP | WS_CLIPCHILDREN;
static constexpr u32 FixedStyle = WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_BORDER | WS_CLIPCHILDREN;
static constexpr u32 ResizableStyle = WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME | WS_CLIPCHILDREN;
static constexpr u32 BorderlessStyle = WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS;

u32 pWindow::minimumStatusHeight = 0;

Expand Down Expand Up @@ -423,6 +424,15 @@ auto pWindow::_statusHeight() const -> s32 {
return height;
}

auto pWindow::setBorderless(bool borderless) -> void {
DWORD newframeStyle = (borderless) ? BorderlessStyle : ResizableStyle;
DWORD oldframeStyle = static_cast<LONG>(GetWindowLongPtrW(hwnd, GWL_STYLE));
if (newframeStyle != oldframeStyle) {
SetWindowLongPtrW(hwnd, GWL_STYLE, static_cast<LONG>(newframeStyle));
SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE);
ShowWindow(hwnd, SW_SHOW);
}
}
}

#endif
3 changes: 2 additions & 1 deletion hiro/windows/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct pWindow : pObject {
auto remove(sSizable sizable) -> void;
auto remove(sStatusBar statusBar) -> void;
auto setBackgroundColor(Color color) -> void;
auto setBorderless(bool borderless) -> void;
auto setDismissable(bool dismissable) -> void;
auto setDroppable(bool droppable) -> void;
auto setEnabled(bool enabled) -> void override;
Expand All @@ -34,7 +35,7 @@ struct pWindow : pObject {
auto setModal(bool modal) -> void;
auto setResizable(bool resizable) -> void;
auto setTitle(string text) -> void;
auto setVisible(bool visible) -> void override;
auto setVisible(bool visible) -> void override;

auto modalIncrement() -> void;
auto modalDecrement() -> void;
Expand Down
Loading