dylanaraps / sowm

An itsy bitsy floating window manager (220~ sloc!).
MIT License
915 stars 73 forks source link

Close window instead of killing it #99

Closed broccoli5 closed 4 years ago

broccoli5 commented 4 years ago

Hi, new user here. I noticed that sowm kills windows instead of closing them. It wouldn't be that big of a deal if Firefox didn't try to restore session every time I open it.

I did found this issue: https://github.com/dylanaraps/sowm/pull/60. And I see that it has been merged with master but, it isn't (??)

https://github.com/dylanaraps/sowm/blob/95596f43aac5f191d96f51290981e860f45eaa55/sowm.c#L124-L126

I tried to patch it with the diff in the mentioned issue, but after that I couldn't close windows at all...

dylanaraps commented 4 years ago

Yes. The commit for #60 broke things. This is the behavior I personally desire which is why sowm works this way. A patch can be written for normal close. Thanks for opening this issue.

Abh15h3k commented 4 years ago

The patch breaks closing windows because of how the XEvent is passed. while writing my own window manager. i tried to send the close event like it is in the diff. didnt work for me.

so i explicitly created a XEvent variable and set the required fields. like so.

 void win_kill(const Arg arg) {
    if (!cur) return;
    XEvent ev;
    ev.type                 = ClientMessage;
    ev.xclient.window       = cur->w;
    ev.xclient.message_type = XInternAtom(d, "WM_PROTOCOLS", True);
    ev.xclient.format       = 32; // EDIT: This line is not there is the diff. i needed this for the XSendEvent to work. with this clients wouldn't close
    ev.xclient.data.l[0]    = XInternAtom(d, "WM_DELETE_WINDOW", True);
    ev.xclient.data.l[1]    = CurrentTime;

    XSendEvent(d, cur->w, False, NoEventMask, &ev);
 }

Note: Closing windows this way will only work if the window supports the DELETE Protocol. for example Xephyr does not support the DELETE Protocol. the only way a window manager can Close(or kill in this case) is by calling XKillClient.

broccoli5 commented 4 years ago

@Abh15h3k Thank you! This works perfectly! I was originally going to borrow some code from spectrwm or bspwm, but I'm not a C programmer so, it could have been interesting to say the least.

I'm not that much worried about the DELETE protocol, I really only use urxvt and Firefox and both work fine

(Also the compiler was complaining about missing ; before XSendEvent so I added one after the CurrentTime)

Maybe make your own diff?

Abh15h3k commented 4 years ago

(Also the compiler was complaining about missing ; before XSendEvent so I added one after the CurrentTime)

whoops. must've copied the wrong thing. they should all end with ;

Maybe make your own diff?

i don't know if i should include the "fix" for windows that don't close with this method. cause that would make the diff rather big. which feels like going against what i see in this window manager. clean, simple, small

broccoli5 commented 4 years ago

whoops. must've copied the wrong thing. they should all end with ;

Ah, thanks ok I did have that feeling

i don't know if i should include the "fix" for windows that don't close with this method. cause that would make the diff rather big. which feels like going against what i see in this window manager. clean, simple, small

I mean this is enough (at least for me). It's still a optional patch, so I wouldn't worry about it not working for everything too much, just point it out.