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

ScreenListener support for macos and windows #21

Open
holotrek opened this issue Feb 22, 2024 · 1 comment
Open

ScreenListener support for macos and windows #21

holotrek opened this issue Feb 22, 2024 · 1 comment

Comments

@holotrek
Copy link

Are ScreenListener events supported on macos and windows? Looking at the code, it seems that the only version that emits events is Linux when displays are added/removed in the following lines:

g_signal_connect_object(display, "monitor-added",

g_signal_connect_object(display, "monitor-removed",

I would like to have that ability on the other systems, but don't have the knowledge enough to know how to modify your code to do so.

As a side note, there's also no documentation on the README going over the event and whether it is supported on different systems.

@holotrek
Copy link
Author

holotrek commented Feb 23, 2024

I have gotten this working with MacOS. If you are running on mac and want to detect when the screen changes, update your pubspec.yml to:

  screen_retriever:
    git:
      url: https://github.com/holotrek/screen_retriever
      ref: "ad04fd32637ac901e1d64d0725ac6343a0347255"

Then mark a widget as inheriting ScreenListener and add an event that can update your display list, i.e.:

class MyDisplaysState extends State<MyDisplays> with ScreenListener {
  @override
  void initState() {
    super.initState();
    screenRetriever.addListener(this);
  }

  @override
  void onScreenEvent(String eventName) {
    // eventName may be "monitor-added" or "monitor-removed"
    super.onScreenEvent(eventName);
    setState(() {});
  }

  @override
  void dispose() {
    screenRetriever.removeListener(this);
    super.dispose();
  }
}

I'll post back with an updated ref if I get this working with Windows and also will submit a PR.

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

No branches or pull requests

1 participant