crgimenes / neko

Neko is a cross-platform cursor-chasing cat. This is the reimplementation write in Go.
BSD 2-Clause "Simplified" License
414 stars 40 forks source link

Guide to run neko on i3wm #21

Closed SolsticeSpectrum closed 8 months ago

SolsticeSpectrum commented 9 months ago

neko-go doesn't work well with workspaces and also i3wm border/picom can be annoying but I found solutions to all problems.

First in i3wm config add these lines

for_window [class="GLFW-Application"] border none
exec --no-startup-id $HOME/.local/bin/neko.sh

the latter will be explained later

Then in picom.conf add this if you use shadows

shadow-exclude = [
    "class_g = 'GLFW-Application'"
];

Now create a new file in .local/bin called neko.sh and in it add this

#!/bin/bash

# Kill existing neko-go processes and start a new one
restart_neko() {
    killall neko-go 2>/dev/null
    nohup neko-go -speed 1 -scale 1 >/dev/null 2>&1 &
}

# Initial start
restart_neko

# Listen for workspace change events from i3
i3-msg -t subscribe -m '[ "workspace" ]' | jq --unbuffered -c 'select(.change == "focus")' |
while read -r event; do
    restart_neko
done

this script restarts neko-go on workspace changes to always put neko on the current workspace
I tried moving the neko window to the new workspace but it often just vanishes into thin air so this
solution is less prune to errors, keep in mind that -speed 1 -scale 1 has been used for preference
change these accordingly

SolsticeSpectrum commented 9 months ago

Some notes for the author: @crgimenes It would be beneficial for neko-go to have it's own class name instead of just GLFW-Application Also adding proper WM name would be nice too. Currently this one is left empty image

Maybe add workspace hopping for tiling window managers

crgimenes commented 9 months ago

Hi @DarkReaper231, To change these parameters, I need to change Ebitengine (the game engine I use) because it is what takes care of creating the windows and doing all the GLFW manipulation.

I'm looking to see if there is an easy way to do this.

crgimenes commented 9 months ago

Possible workaround using CGO.

#cgo LDFLAGS: -lX11
#include <X11/Xlib.h>
#include <stdlib.h>

void setWMProperties(Display* display, Window window, const char* wmClass, const char* wmName) {
    XClassHint *classHint = XAllocClassHint();
    if (classHint != NULL) {
        classHint->res_name = (char*)wmName;
        classHint->res_class = (char*)wmClass;
        XSetClassHint(display, window, classHint);
        XFree(classHint);
    }
}

It would still be necessary to consider conditional compilation for other platforms and differences between X11 and Wayland.

SolsticeSpectrum commented 9 months ago

@crgimenes Does this fix the issue with vanishing neko as well? Btw neko vanishes if you have video on fullscreen for long enough as well. It vanishes if you change workspaces too quickly or keep the cat on unfocused workspace for long enough.

ebiten.SetRunnableOnUnfocused(true) sounds like something that could be related to this

crgimenes commented 9 months ago

Does this fix the issue with vanishing neko as well? Btw neko vanishes if you have video on fullscreen for long enough as well. It vanishes if you change workspaces too quickly or keep the cat on unfocused workspace for long enough.

I'll try to reproduce this issue, but it isn't effortless because I don't have any Linux with a graphical environment.

Is there any relevant information in your system logs?

SolsticeSpectrum commented 9 months ago

I'll check that

superloach commented 8 months ago

I think perhaps Ebitengine should set the WM class to something more recognisable? Even if it's not exposed in an API, at least defaulting to the binary name or window title would be a lot more useful than "GLFW-Application".

superloach commented 8 months ago

Correction: https://pkg.go.dev/github.com/hajimehoshi/ebiten/v2#RunGameOptions.X11ClassName 🎉 in Ebitengine v2.7.0

superloach commented 8 months ago

Also, does https://i3wm.org/docs/userguide.html#_sticky_floating_windows not work here? A restart script sounds unnecessary to me if sticky functions correctly.

crgimenes commented 8 months ago

Hey, guys,

I made the change and adjusted X11ClassName and X11InstanceName, but I don't have any Linux with a graphical interface around here, so I don't know if the effect was what we expected.

Can anyone test it for me?

Thank you, gays, for being so helpful.

SolsticeSpectrum commented 8 months ago

@superloach sticky works flawlessly! Thanks! So the bash script is no longer needed.

SolsticeSpectrum commented 8 months ago

@crgimenes All WM ids are indeed set so the update worked! image

I'm gonna do a quick test if the bug with vanishing cat with fullscreen YouTube videos is gone. EDIT: It still persists but with sticky enabled as suggested by @superloach it appears again after switching workspaces so not a big deal

crgimenes commented 8 months ago

Full screen is an even bigger problem on macOS; at the moment, I can't change it because I don't have access to the window's properties.

I will close the issue; feel free to open it again if you think it is necessary.