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

Linux: fix frameless window & background color #250

Merged
merged 4 commits into from Dec 11, 2022
Merged

Linux: fix frameless window & background color #250

merged 4 commits into from Dec 11, 2022

Conversation

jpnurmi
Copy link
Contributor

@jpnurmi jpnurmi commented Dec 8, 2022

This is a replacement of #248 and implements support for frameless windows and background colors in a way that it doesn't draw over HdyWindow's shadows nor needs any redraw tricks.

@jpnurmi

This comment was marked as resolved.

@jpnurmi jpnurmi marked this pull request as draft December 8, 2022 12:34
Must not be called for HdyWindow or it won't render the background.
@jpnurmi
Copy link
Contributor Author

jpnurmi commented Dec 8, 2022

Before

The background was not drawn at all unless the window was made frameless.

Normal Frameless
image image

After

The background color and the window decorations are disconnected. You can set a background color without making the window frameless. As a bonus, the background color works for Handy windows too.

Normal Frameless Handy
image image image
main.dart
import 'package:flutter/material.dart';
import 'package:window_manager/window_manager.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await windowManager.ensureInitialized();
  // await windowManager.setAsFrameless();
  await windowManager.setBackgroundColor(Colors.white);

  final backgroundColor = ValueNotifier(Colors.white);

  runApp(
    MaterialApp(
      home: Scaffold(
        backgroundColor: Colors.transparent,
        appBar: AppBar(
          title: Text('window_manager_example'),
        ),
        body: Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                for (final color in [Colors.red, Colors.green, Colors.blue])
                  ElevatedButton(
                    style: ElevatedButton.styleFrom(backgroundColor: color),
                    child: Text(color.value.toRadixString(16)),
                    onPressed: () {
                      backgroundColor.value =
                          color.withOpacity(backgroundColor.value.opacity);
                      windowManager.setBackgroundColor(backgroundColor.value);
                    },
                  ),
              ],
            ),
            ValueListenableBuilder<Color>(
              valueListenable: backgroundColor,
              builder: (context, color, child) {
                return Slider(
                  value: color.opacity,
                  onChanged: (value) {
                    backgroundColor.value = color.withOpacity(value);
                    windowManager.setBackgroundColor(backgroundColor.value);
                  },
                );
              },
            ),
          ],
        ),
      ),
    ),
  );
}

@jpnurmi jpnurmi marked this pull request as ready for review December 8, 2022 13:01
@lijy91 lijy91 merged commit 52ba39d into leanflutter:main Dec 11, 2022
@jpnurmi jpnurmi deleted the linux-background-color branch December 11, 2022 09:05
lijy91 pushed a commit that referenced this pull request Jan 3, 2023
* [linux] clean up unused includes

- cairo is unused since #250
- utsname and cstring are leftovers from the flutter plugin template

* [linux] change the last remaining strcmp() to g_strcmp0()

While one PR was changing strcmp()'s to g_strcmp0(), this piece of code
was added in another PR. Use the same method here as well, just for the
sake of aesthetics and consistency.
obiwanzenobi pushed a commit to obiwanzenobi/window_manager that referenced this pull request May 25, 2023
* Linux: fix frameless window & background color

* Remove gtk_widget_set_app_paintable()

Must not be called for HdyWindow or it won't render the background.

* Add window selector

Co-authored-by: LiJianying <lijy91@foxmail.com>
obiwanzenobi pushed a commit to obiwanzenobi/window_manager that referenced this pull request May 25, 2023
* [linux] clean up unused includes

- cairo is unused since leanflutter#250
- utsname and cstring are leftovers from the flutter plugin template

* [linux] change the last remaining strcmp() to g_strcmp0()

While one PR was changing strcmp()'s to g_strcmp0(), this piece of code
was added in another PR. Use the same method here as well, just for the
sake of aesthetics and consistency.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants