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

allow layershell to support both docked and windowed applications #121

Open
Gibbz opened this issue Jan 26, 2025 · 12 comments
Open

allow layershell to support both docked and windowed applications #121

Gibbz opened this issue Jan 26, 2025 · 12 comments

Comments

@Gibbz
Copy link

Gibbz commented Jan 26, 2025

I'm working on a virtual keyboard with some unusual features. Is there a way to support both the 'docked' style keyboard (what i have currently) and also a 'windowed' style version from the same app? Id like to add a switch in the settings the user can flip to a windowed version and back.

my main file is here.
https://github.com/bit-shift-io/surfboard/blob/main/src/main.rs

Ive tried setting it as a standard iced Application for window, but that means i need to duplicate my modules as the imports are completely different.... And i want it to stay on top....

@Decodetalkers
Copy link
Collaborator

Decodetalkers commented Jan 26, 2025

I'm working on a virtual keyboard with some unusual features. Is there a way to support both the 'docked' style keyboard (what i have currently) and also a 'windowed' style version from the same app? Id like to add a switch in the settings the user can flip to a windowed version and back.

my main file is here. https://github.com/bit-shift-io/surfboard/blob/main/src/main.rs

Ive tried setting it as a standard iced Application for window, but that means i need to duplicate my modules as the imports are completely different.... And i want it to stay on top....

I think you can realize this feature by set the margin and anchor together. You can set anchor to empty and set the margin and size, make it show in the special position on the screen

@Gibbz
Copy link
Author

Gibbz commented Jan 27, 2025

Okay great. I've been paying with that and it's working okay so far.

I should be able to draw my own window decoration and drag it around by adjusting the margin according to mouse position, right?

@Decodetalkers
Copy link
Collaborator

Okay great. I've been paying with that and it's working okay so far.

I should be able to draw my own window decoration and drag it around by adjusting the margin according to mouse position, right?

Decoration... I do not know.. seems the protocol of layershell does not have a field for window decoration.. so you mean client decoration right? Then it will be ok.

Yes, it should be possible, by adjusting the margin, you can place the window anywhere. But according to the mouse poison.. seems there's no way to listen to the mouse position move event in the Wayland protocol..

I see, you mean drag the window. If subscribing to the event of iced, you should get the movement of the mouse, then it will be possible I think

@Gibbz
Copy link
Author

Gibbz commented Jan 28, 2025

Thanks. Yes client side decorations. I'll close this as I'm thinking it should work from my tests so far

@Gibbz Gibbz closed this as completed Jan 28, 2025
@Gibbz
Copy link
Author

Gibbz commented Jan 30, 2025

Hi,

Im re-opening this as im stuck. How can i find the layershell settings from within my app? I need access to the layershell settings so i can check the current margin, and the current anchor. From there I can then move the application....

https://docs.rs/iced_layershell/latest/iced_layershell/settings/struct.LayerShellSettings.html

@Gibbz Gibbz reopened this Jan 30, 2025
@Decodetalkers
Copy link
Collaborator

Hi,

Im re-opening this as im stuck. How can i find the layershell settings from within my app? I need access to the layershell settings so i can check the current margin, and the current anchor. From there I can then move the application....

https://docs.rs/iced_layershell/latest/iced_layershell/settings/struct.LayerShellSettings.html

Emm.. You mean you need to get the status from the application.. now I do not store any layershell settings in the application, so there is no way to get the current one. Maybe you can save the status before you set it?

@Gibbz
Copy link
Author

Gibbz commented Jan 30, 2025

So I need to add my own run() function.. And store a reference to the settings?

@Decodetalkers
Copy link
Collaborator

Decodetalkers commented Jan 30, 2025

So I need to add my own run() function.. And store a reference to the settings?

What do you mean? I think you can return the message to set the margin and anchor, that time you can remember the margin and anchor. You can read the examples.

https://github.com/waycrate/exwlshelleventloop/blob/master/iced_examples%2Fcounter%2Fsrc%2Fmain.rs#L98-L118

I think you can take these as example

@Gibbz
Copy link
Author

Gibbz commented Jan 30, 2025

Oh yes I understand what you mean. Okay 👌 ill try that

@Gibbz
Copy link
Author

Gibbz commented Jan 31, 2025

ok ive got it half working. Its got some issues. The problem seems to be that the margin task has some kind of delay. When the margin is updated the window jumps back to an older position. This change causes the mouse cursor to register a different position.

So the only way around this i can see is to subscribe to the margin change and hopefully reset the movement code from there?

  1. How can i subscribe to both IcedEvent and Margin changes?
  2. Do you have any suggestions on how i can work around this issue?
  3. Is there a way to get the mouses absolute screen position instead?
  4. Is there a way to not use a margin to move a "window" around?
  5. Is there a way to get the screen resolution?
    fn subscription(&self) -> Subscription<Self::Message> {
        event::listen()
            .map(MainMessage::IcedEvent)
            .map(MainMessage::MarginChange(())) // <- doesnt work
    }

@Decodetalkers
Copy link
Collaborator

ok ive got it half working. Its got some issues. The problem seems to be that the margin task has some kind of delay. When the margin is updated the window jumps back to an older position. This change causes the mouse cursor to register a different position.

So the only way around this i can see is to subscribe to the margin change and hopefully reset the movement code from there?

  1. How can i subscribe to both IcedEvent and Margin changes?
  2. Do you have any suggestions on how i can work around this issue?
  3. Is there a way to get the mouses absolute screen position instead?
  4. Is there a way to not use a margin to move a "window" around?
  5. Is there a way to get the screen resolution?
    fn subscription(&self) -> Subscription<Self::Message> {
        event::listen()
            .map(MainMessage::IcedEvent)
            .map(MainMessage::MarginChange(())) // <- doesnt work
    }

It will never send the margin change event.. iced cannot resend custom event currently.. maybe you can use time to control the sending frequency, and wait for the wm to finish the margin change.

@Gibbz
Copy link
Author

Gibbz commented Jan 31, 2025

Okay, that's an option I can try. I don't think it will work actually. I need to know when the margin has changed and the window redrawn, so I can start the mouse position calculation again. Any delay to that and it will be janky.

I've filled a bug with iced here: iced-rs/iced#2773

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants