phanirithvij / mpv-config

My mpv config
2 stars 0 forks source link

Linux portability? #1

Open trappedinspacetime opened 3 years ago

trappedinspacetime commented 3 years ago

Is it possible to port save_last_pos.lua to Linux?

phanirithvij commented 3 years ago

I don't have much experience with Linux window management but you can start here https://unix.stackexchange.com/q/14159 https://unix.stackexchange.com/a/359311 Let me know if you can implement it or I'll try (but I don't have enough spare time so it's very likely to take a week or more)

trappedinspacetime commented 3 years ago

@phanirithvij Thank you for responding and your help. I created two scripts; save-pos bash script:

    #!/bin/bash
    xdotool search --sync --class mpv getwindowgeometry > ~/.config/mpv/scripts/last_window_coords.txt

win-pos.js:

      function on_exit() {
          var winpossave = mp.command_native({
              name: "subprocess",
              playback_only: false,
              capture_stdout: true,
              args : ["save-pos"]
          });
      }
      mp.register_event("shutdown", on_exit);

Output of last_window_coords.txt:

      Window 102760450
        Position: 5,279 (screen: 0)
        Geometry: 960x480

I use notorius X11, so output of window position via xdotool is not reliable, sometimes it fails to reach MPV window on the screen. MPV provides a native property for pid mp.utils.getpid() but provides no window id property. In X11 you need a hacky way to obtain window id from its pid https://stackoverflow.com/questions/151407/how-to-get-an-x11-window-from-a-process-id In the first link you posted above there is xgeometry.c, I built it, it works well but it needs window id instead of pid

summing-up: it kind of works.

trappedinspacetime commented 3 years ago

I made it work using the following scripts: https://github.com/trappedinspacetime/mpv-save-window-position