Skip to content
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

Borderless Mode (Windows) #1394

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
34 changes: 32 additions & 2 deletions desktop-ui/desktop-ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ auto nall::main(Arguments arguments) -> void {
return settings.paths.saves;
});

#if defined(PLATFORM_WINDOWS)
u32 SettingsGeneralsBorderless = 0;
MartyShepard marked this conversation as resolved.
Show resolved Hide resolved
#endif

if(arguments.take("--fullscreen")) {
program.startFullScreen = true;
}
Expand Down Expand Up @@ -112,11 +116,14 @@ 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");
print(" --dump-all-settings Show a list of all existing settings and exit\n");
print(" --no-file-prompt Do not prompt to load (optional) additional roms (eg: 64DD)\n");
print(" --no-file-prompt Do not prompt to load (optional) additional roms (eg: 64DD)\n");
MartyShepard marked this conversation as resolved.
Show resolved Hide resolved
print("\n");
print("Available Systems:\n");
print(" ");
Expand All @@ -126,7 +133,19 @@ auto nall::main(Arguments arguments) -> void {
print("\n");
return;
}


#if defined(PLATFORM_WINDOWS)
// Randloses Fenster Commandline --------- BEGIN
if (arguments.take("--noBorderless")) {
settings.general.sBorderless = false;
MartyShepard marked this conversation as resolved.
Show resolved Hide resolved
SettingsGeneralsBorderless = 1;
}
if (arguments.take("--Borderless")) {
settings.general.sBorderless = true;
SettingsGeneralsBorderless = 2;
}
#endif

if(arguments.take("--dump-all-settings")) {
function<void(const Markup::Node&, string)> dump;
dump = [&](const Markup::Node& node, string prefix) -> void {
Expand All @@ -144,6 +163,17 @@ auto nall::main(Arguments arguments) -> void {
if(file::exists(argument)) program.startGameLoad.append(argument);
}

#if defined(PLATFORM_WINDOWS)
/* Force and Change Settings By Commandline */
MartyShepard marked this conversation as resolved.
Show resolved Hide resolved
if ( SettingsGeneralsBorderless > 0)
MartyShepard marked this conversation as resolved.
Show resolved Hide resolved
{
if ( SettingsGeneralsBorderless == 1)
MartyShepard marked this conversation as resolved.
Show resolved Hide resolved
settings.general.sBorderless = false;

if ( SettingsGeneralsBorderless == 2)
settings.general.sBorderless = true;
}
#endif
Instances::presentation.construct();
Instances::settingsWindow.construct();
Instances::toolsWindow.construct();
Expand Down
7 changes: 7 additions & 0 deletions desktop-ui/input/hotkeys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ 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("Fork Borderless Window").onPress([&] {
MartyShepard marked this conversation as resolved.
Show resolved Hide resolved
program.UpdateBorderless();
settings.save();
MartyShepard marked this conversation as resolved.
Show resolved Hide resolved
}));
#endif
}

auto InputManager::pollHotkeys() -> void {
Expand Down
13 changes: 13 additions & 0 deletions desktop-ui/presentation/presentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ Presentation::Presentation() {
}
if(visible()) resizeWindow();
}).doToggle();
#if defined(PLATFORM_WINDOWS)
showBorderlessSetting.setText("Borderless Window").setChecked(settings.general.sBorderless).onToggle([&] {
settings.general.sBorderless = showBorderlessSetting.checked();
if (!showBorderlessSetting.checked()) {
Window::setBorderless(false);
}
else {
Window::setBorderless(true);
}
if (visible()) resizeWindow();
settings.save();
}).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;
MartyShepard marked this conversation as resolved.
Show resolved Hide resolved
#endif

//utility.cpp
auto pause(bool) -> void;
Expand Down
16 changes: 16 additions & 0 deletions desktop-ui/program/status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,19 @@ 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 {

if (settings.general.sBorderless == true){
MartyShepard marked this conversation as resolved.
Show resolved Hide resolved
settings.general.sBorderless = false;
presentation.Window::setBorderless(false);
presentation.showBorderlessSetting.setChecked(false);
}
else {
MartyShepard marked this conversation as resolved.
Show resolved Hide resolved
settings.general.sBorderless = true;
presentation.Window::setBorderless(true);
presentation.showBorderlessSetting.setChecked(true);
}
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.sBorderless);
#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 sBorderless = false;
MartyShepard marked this conversation as resolved.
Show resolved Hide resolved
#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
7 changes: 6 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 All @@ -65,11 +67,14 @@ struct mWindow : mObject {
auto sizable() const -> Sizable;
auto statusBar() const -> StatusBar;
auto title() const -> string;



//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
49 changes: 47 additions & 2 deletions hiro/windows/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ auto pWindow::frameMargin(s32 width) const -> Geometry {
SendMessage(hwnd, WM_NCCALCSIZE, (WPARAM)false, (LPARAM)&rcTemp);
//adjust our previous calculation to compensate for menu wrapping
rc.bottom += rcTemp.top;
}
} else {
if (bBorderLess){
rc.bottom = 458; // TODO Hardcoded ...
MartyShepard marked this conversation as resolved.
Show resolved Hide resolved
}
}
auto& efb = state().fullScreen ? settings.efbPopup : !state().resizable ? settings.efbFixed : settings.efbResizable;
return {
abs(rc.left) - efb.x,
Expand Down Expand Up @@ -422,7 +426,48 @@ auto pWindow::_statusHeight() const -> s32 {
}
return height;
}

enum class Style : DWORD {
windowed = WS_OVERLAPPEDWINDOW | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
aero_borderless = WS_POPUP | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX,
basic_borderless = WS_POPUP | WS_THICKFRAME | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX,
FixedStyle = WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_BORDER | WS_CLIPCHILDREN,
ResizableStyle = WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME | WS_CLIPCHILDREN,
Marty_Borderless = WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS ,
};

auto composition_enabled() -> bool {
MartyShepard marked this conversation as resolved.
Show resolved Hide resolved
BOOL composition_enabled = FALSE;
bool success = ::DwmIsCompositionEnabled(&composition_enabled) == S_OK;
return composition_enabled && success;
}

auto set_shadow(HWND handle, bool enabled) -> void {
if (composition_enabled()) {
static const MARGINS shadow_state[2]{ { 0,0,0,0 },{ 1,1,1,1 } };
::DwmExtendFrameIntoClientArea(handle, &shadow_state[enabled]);
}
}

auto select_borderless_style() -> Style {
return composition_enabled() ? Style::aero_borderless : Style::basic_borderless;
}

auto pWindow::setBorderless(bool borderless) -> void {

bBorderLess = borderless;

Style new_style = (borderless) ? Style::Marty_Borderless : Style::ResizableStyle;
Style old_style = static_cast<Style>(::GetWindowLongPtrW(hwnd, GWL_STYLE));

if (new_style != old_style) {
::SetWindowLongPtrW(hwnd, GWL_STYLE, static_cast<LONG>(new_style));

set_shadow(hwnd, true && (new_style != Style::ResizableStyle));

::SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE);
::ShowWindow(hwnd, SW_SHOW);
}
}
}

#endif
9 changes: 7 additions & 2 deletions 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,8 +35,8 @@ 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;
auto windowProc(HWND, UINT, WPARAM, LPARAM) -> maybe<LRESULT>;
Expand All @@ -51,7 +52,11 @@ struct pWindow : pObject {
HBRUSH hbrush = nullptr;
COLORREF hbrushColor = 0;
Geometry windowedGeometry{128, 128, 256, 256};
bool bBorderLess = false;
MartyShepard marked this conversation as resolved.
Show resolved Hide resolved
bool focus = false;



};

}
Expand Down