kanshi icon indicating copy to clipboard operation
kanshi copied to clipboard

sway reload breaks kanshi config

Open itapai opened this issue 5 years ago • 14 comments

This is my config

{
    output eDP-1 enable mode 1920x1080
}
{
    output eDP-1 disable
    output "Dell Inc. DELL U3415W F1T1W88R0A1L" enable mode 3440x1440
}

On sway start, profiles are applied correctly. When i reload sway (mod+shift+r), both profiles get applied, resulting in both displays being turned on. Kanshi is started via sway config (exec kanshi). If I rerun kanshi from the terminal, profiles gets applied correcly.

Is kanshi meant to be started this way (via sway config)?

Running it on archlinux via aur packages (kanshi-git, sway-git, wlroots-git, ... the whole shabang )

itapai avatar Jul 27 '19 20:07 itapai

This is kind of a sway bug. It should keep the configuration on reload. Or request that kanshi sends the configuration again? I'm not sure how it could do this.

emersion avatar Jul 28 '19 15:07 emersion

Hi,

I have investigated this and it appears that sway sends the right information, but kanshi does not react to that, because of the check below. Removing that check makes kanshi react to the done() event after the changes induced by the reload have been sent.

This happens because kanshi never changes its current profile pointer. The struct is updated in place, and the check fails.

diff --git a/main.c b/main.c
index c25e2bb..768e381 100644
--- a/main.c
+++ b/main.c
@@ -118,9 +133,7 @@ static struct kanshi_mode *match_mode(struct kanshi_head *head,
 static void apply_profile(struct kanshi_state *state,
                struct kanshi_profile *profile,
                struct kanshi_profile_output **matches) {
-       if (state->current_profile == profile) {
-               return;
-       }
+       // TODO: Skip if nothing changed.
 
        struct kanshi_pending_profile *pending = calloc(1, sizeof(*pending));
        pending->state = state;

layus avatar Aug 09 '19 15:08 layus

Well, I guess it depends on what we want. Do we want kanshi to apply configs only when a new config matches, or do we want it to enforce the given config all the time ?

If we are to solve this in sway (keep the current config), then why is sway not able to collect it from the state of the monitor themselves ?

layus avatar Aug 09 '19 15:08 layus

This issue seems to break my current configuration. Right now I have the following in my sway config

exec kanshi

as soon as I reload sway as mentioned above - the wrong configuration seems to be picked up. Is there a workaround for this or is reloading sway's config currently broken?

MichaelAquilina avatar Sep 03 '19 09:09 MichaelAquilina

Using kanshi + sway relaod is broken. You can call kanshi (and kill it afterward ) after each sway reload to force update it's config.

Seems like a good fix would make sway keep outputs config on reload (but sway has output directives that could have changed and need to be re-applied).

layus avatar Sep 03 '19 09:09 layus

Found a very effective solution, that may not prove as temorary as expected (hear: It could become the official solution).

exec_always pkill kanshi; exec kanshi

It ensures a full restart (reload) of kanshi on every sway reload. The second exec is to avoid a leftover sh -c invocation. It is not a sway command but part of the pkill kanshi; exec kanshi shell script.

:sparkles: Expect some flickering :sparkles:

layus avatar Sep 16 '19 08:09 layus

The same technique can be used to launch swayidle (in case of parameters change) and waybar (if you use it).

layus avatar Sep 16 '19 08:09 layus

@layus when i reload and if I have an external display connected, all my windows close. do you experience this as well? if i dont have an external display connected, it works fine

itapai avatar Sep 18 '19 18:09 itapai

@itapai I have also experienced this issue several times. I've had to stop using kanshi until I can figure a way to work round it / fix the issue

MichaelAquilina avatar Sep 18 '19 21:09 MichaelAquilina

when i reload and if I have an external display connected, all my windows close

This should fix it: https://github.com/swaywm/wlroots/pull/1765

emersion avatar Sep 18 '19 21:09 emersion

Sway could destroy all output-management heads and re-add them to ask clients to configure them again.

emersion avatar Nov 05 '19 07:11 emersion

Is the best solution to this still exec_always pkill kanshi; exec kanshi ?

fourstepper avatar May 06 '20 21:05 fourstepper

@fourstepper I just very successfully applied that sway line from @layus and can't find a better answer elsewhere. I wonder if this line should be put in some kind of doc? I had a hard time finding out how to integrate kanshi with sway due to the reload issue. Particularly I think pywal was causing a reload of sway config right away so kanshi wouldn't work with a simple exec in sway config even on startup. With the exec_always kanshi survives the sway reconfig that pywal causes when loaded in sway config at startup. Thanks!

danjclegg avatar Sep 11 '20 21:09 danjclegg

If you use systemd to run kanshi as a user service, you can do:

exec_always "systemctl --user restart kanshi.service"

yaymukund avatar Apr 02 '21 11:04 yaymukund