Skip to content

Commit

Permalink
New window apis (#891)
Browse files Browse the repository at this point in the history
* remove unused swift-ui frontend

* introduce macos-use-shadow, windows-corner-preference, windows-use-undecorated-shadow and windows-use-no-redirection-bitmap

* fix imports

* use Option<bool> to windows apis

* fix cargo fmt

* get from option

* fix lint
  • Loading branch information
raphamorim authored Jan 9, 2025
1 parent 6a2038e commit ee0b71b
Show file tree
Hide file tree
Showing 20 changed files with 185 additions and 1,000 deletions.
131 changes: 108 additions & 23 deletions docs/docs/config/window.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,90 @@ title: 'window'
language: 'en'
---

- `width` - define the initial window width.
### width

- Default: `600`
Define the initial window width.

- `height` - define the initial window height.
- Default: `600`

- Default: `400`
Example:

- `mode` - define how the window will be created
```toml
[window]
width = 600
```

- `Windowed` (default) is based on width and height
- `Maximized` window is created with maximized
- `Fullscreen` window is created with fullscreen
### height

- `opacity` Set window background opacity.
Define the initial window height.

- Default: `1.0`.
- Default: `400`

- `blur` Set blur on the window background. Changing this config requires restarting Rio to take effect.
Example:

- Default: `false`.
```toml
[window]
height = 400
```

- `background-image` Set an image as background.
### mode

- Default: `None`
Define how the window will be created

- `decorations` - Set window decorations
- `Enabled` (default for Windows/Linux/BSD) enable window decorations.
- `Disabled` disable all window decorations.
- `Transparent` (default for MacOS) window decorations with transparency.
- `Buttonless` remove buttons from window decorations.
- `Windowed` (default) is based on width and height
- `Maximized` window is created with maximized
- `Fullscreen` window is created with fullscreen

Example:

```toml
[window]
width = 600
height = 400
mode = "Windowed"
opacity = 1.0
```

### opacity

Set window background opacity.

- Default: `1.0`.

Example:

```toml
[window]
opacity = 0.5
```

### blur

Set blur on the window background. Changing this config requires restarting Rio to take effect.

- Default: `false`.

```toml
[window]
blur = false
```

### background-image

Set an image as background.

- Default: `None`

### decorations

Set window decorations.

- `Enabled` (default for Windows/Linux/BSD) enable window decorations.
- `Disabled` disable all window decorations.
- `Transparent` (default for MacOS) window decorations with transparency.
- `Buttonless` remove buttons from window decorations.

Example:

```toml
[window]
decorations = "Enabled"
```

Expand Down Expand Up @@ -97,4 +140,46 @@ You can use MacOS unified titlebar by config, it's disabled by default.
macos-use-unified-titlebar = false
```

![Demo unified titlebar](/assets/demos/demo-macos-unified-titlebar.png)
![Demo unified titlebar](/assets/demos/demo-macos-unified-titlebar.png)

### MacOS: Enable or disable shadow

You can enable window shadow on MacOS by config, it's disabled by default.

```toml
[window]
macos-use-shadow = true
```

### Windows: Corner Preference

Describes how the corners of a Microsoft Windows window should look like.

Options: `Default`, `DoNotRound`,`Round` and `RoundSmall`

```toml
[window]
windows-corner-preference = "Round"
```

### Windows: Undecorated shadow

Microsoft Windows specific.

Shows or hides the background drop shadow for undecorated windows.

```toml
[window]
windows-use-undecorated-shadow = false
```

### Windows: use-no-redirection-bitmap

Microsoft Windows specific.

This sets `WS_EX_NOREDIRECTIONBITMAP`.

```toml
[window]
windows-use-no-redirection-bitmap = false
```
4 changes: 4 additions & 0 deletions docs/docs/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ language: 'en'
## 0.2.3 (unreleased)

- Fixed: Nix build [#853](https://github.com/raphamorim/rio/pull/853).
- Support to `window.macos-use-shadow` (enable or disable shadow on MacOS).
- Support to `window.windows-corner-preference` (options: `Default`, `DoNotRound`,`Round` and `RoundSmall`).
- Support to `window.windows-use-undecorated-shadow` (default is enabled).
- Support to `window.windows-use-no-redirection-bitmap` (This sets `WS_EX_NOREDIRECTIONBITMAP`).
- Support for Unicode 16 characters.
- Support to line height.
- Fixed: Deb package name 'rio' conflicts with existing one in Ubuntu [#876](https://github.com/raphamorim/rio/issues/876).
Expand Down
47 changes: 46 additions & 1 deletion frontends/rioterm/src/router/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ pub fn create_window_builder(
window_builder = window_builder.with_name(APPLICATION_ID, "");
}

#[cfg(target_os = "windows")]
{
use rio_window::platform::windows::WindowAttributesExtWindows;
if let Some(use_undecorated_shadow) = config.window.windows_use_undecorated_shadow
{
window_builder =
window_builder.with_undecorated_shadow(use_undecorated_shadow);
}

if let Some(use_no_redirection_bitmap) =
config.window.windows_use_no_redirection_bitmap
{
// This sets WS_EX_NOREDIRECTIONBITMAP.
window_builder =
window_builder.with_no_redirection_bitmap(use_no_redirection_bitmap);
}
}

#[cfg(target_os = "macos")]
{
use rio_window::platform::macos::WindowAttributesExtMacOS;
Expand Down Expand Up @@ -165,9 +183,36 @@ pub fn configure_window(winit_window: &Window, config: &Config) {
bg_color.b,
config.window.opacity as f64,
);
winit_window.set_has_shadow(!is_transparent);

if !config.window.macos_use_shadow {
winit_window.set_has_shadow(false);
}
}

#[cfg(target_os = "windows")]
{
use rio_backend::config::window::WindowsCornerPreference;
use rio_window::platform::windows::WindowExtWindows;

if let Some(with_corner_preference) = &config.window.windows_corner_preference {
let preference = match with_corner_preference {
WindowsCornerPreference::Default => {
rio_window::platform::windows::CornerPreference::Default
}
WindowsCornerPreference::DoNotRound => {
rio_window::platform::windows::CornerPreference::DoNotRound
}
WindowsCornerPreference::Round => {
rio_window::platform::windows::CornerPreference::Round
}
WindowsCornerPreference::RoundSmall => {
rio_window::platform::windows::CornerPreference::RoundSmall
}
};

winit_window.set_corner_preference(preference);
}
}
if let Some(title) = &config.window.initial_title {
winit_window.set_title(title);
}
Expand Down
Loading

0 comments on commit ee0b71b

Please sign in to comment.