JonnyHaystack / i3-resurrect

Simple solution to saving and restoring i3 workspaces
GNU General Public License v3.0
379 stars 19 forks source link

Programs running in urxvt not saved #105

Open danhab99 opened 3 years ago

danhab99 commented 3 years ago

Describe the bug

I work pretty much completely using CLI programs like vim. My default terminal emulator is Urxvt. i3-resurrect doesn't retain the cwd or program that urxvt was running.

To Reproduce Steps to reproduce the behavior:

  1. Install my dotfiles
  2. Setup a urxvt window running vim and some other program like a node script on workspace "2"
  3. Run i3-resurrect save -w 2
  4. Attempt to restore workspace 2 like this: i3-resurrect restore -w 2
  5. Programs don't restore

Expected behavior A clear and concise description of what you expected to happen.

Programs are rerun in accordance to its cmdline

Screenshots

System information (please complete the following information):

Additional context Add any other context about the problem here.

Layout:

{
  "border": "normal",
  "current_border_width": -1,
  "floating": "auto_off",
  "fullscreen_mode": 0,
  "geometry": {
    "x": 0,
    "y": 0,
    "width": 0,
    "height": 0
  },
  "layout": "splitv",
  "marks": [],
  "name": "2",
  "orientation": "vertical",
  "percent": null,
  "scratchpad_state": "none",
  "sticky": false,
  "type": "workspace",
  "workspace_layout": "default",
  "nodes": [
    {
      "border": "normal",
      "current_border_width": -1,
      "floating": "auto_off",
      "fullscreen_mode": 0,
      "geometry": {
        "x": 0,
        "y": 0,
        "width": 0,
        "height": 0
      },
      "layout": "splith",
      "marks": [],
      "name": null,
      "orientation": "horizontal",
      "percent": 0.8,
      "scratchpad_state": "none",
      "sticky": false,
      "type": "con",
      "workspace_layout": "default",
      "nodes": [
        {
          "border": "normal",
          "current_border_width": -1,
          "floating": "auto_off",
          "fullscreen_mode": 0,
          "geometry": {
            "x": 0,
            "y": 0,
            "width": 0,
            "height": 0
          },
          "layout": "splitv",
          "marks": [],
          "name": null,
          "orientation": "vertical",
          "percent": 0.65,
          "scratchpad_state": "none",
          "sticky": false,
          "type": "con",
          "workspace_layout": "default",
          "nodes": [
            {
              "border": "pixel",
              "current_border_width": 0,
              "floating": "auto_off",
              "fullscreen_mode": 0,
              "geometry": {
                "x": 0,
                "y": 0,
                "width": 840,
                "height": 520
              },
              "layout": "splith",
              "marks": [],
              "name": "NERD_tree_1 - (~/Documents/node/cryptochan) - VIM",
              "orientation": "none",
              "percent": 1.0,
              "scratchpad_state": "none",
              "sticky": false,
              "type": "con",
              "workspace_layout": "default",
              "swallows": [
                {
                  "class": "^URxvt$",
                  "instance": "^urxvt$"
                }
              ]
            }
          ]
        },
        {
          "border": "pixel",
          "current_border_width": 0,
          "floating": "auto_off",
          "fullscreen_mode": 0,
          "geometry": {
            "x": 0,
            "y": 0,
            "width": 840,
            "height": 520
          },
          "layout": "splith",
          "marks": [],
          "name": "dan@dan-81c9: ~/Documents/node/cryptochan",
          "orientation": "none",
          "percent": 0.35,
          "scratchpad_state": "none",
          "sticky": false,
          "type": "con",
          "workspace_layout": "default",
          "swallows": [
            {
              "class": "^URxvt$",
              "instance": "^urxvt$"
            }
          ]
        }
      ]
    },
    {
      "border": "pixel",
      "current_border_width": 0,
      "floating": "auto_off",
      "fullscreen_mode": 0,
      "geometry": {
        "x": 0,
        "y": 0,
        "width": 840,
        "height": 520
      },
      "layout": "splith",
      "marks": [],
      "name": "yarn dev",
      "orientation": "none",
      "percent": 0.19999999999999998,
      "scratchpad_state": "none",
      "sticky": false,
      "type": "con",
      "workspace_layout": "default",
      "swallows": [
        {
          "class": "^URxvt$",
          "instance": "^urxvt$"
        }
      ]
    }
  ]
}

Programs:


[
  {
    "command": [
      "/usr/bin/urxvt"
    ],
    "working_directory": "/home/dan"
  },
  {
    "command": [
      "/usr/bin/urxvt"
    ],
    "working_directory": "/home/dan"
  },
  {
    "command": [
      "/usr/bin/urxvt"
    ],
    "working_directory": "/home/dan"
  }
]

This is the project I was working on incase you were wondering.

JonnyHaystack commented 3 years ago

Looks somewhat similar to #96

Expected behavior Programs are rerun in accordance to its cmdline

Would you mind showing the original cmdline of these processes? You can find this by running the following command:

hexdump -C /proc/$(xprop _NET_WM_PID | cut -d ' ' -f3)/cmdline

Then click on one of the urxvt windows, and paste the output here.

danhab99 commented 3 years ago

All 3 of these outputs are from different tiles. Is this a urxvt issue?

00000000  75 72 78 76 74 00                                 |urxvt.|
00000006
00000000  75 72 78 76 74 00                                 |urxvt.|
00000006
00000000  75 72 78 76 74 00                                 |urxvt.|
00000006
JonnyHaystack commented 3 years ago

Uh sorry should've asked before but can you also show the output of ls -l /proc/$(xprop _NET_WM_PID | cut -d ' ' -f3)/cwd

JonnyHaystack commented 3 years ago

Oh I also forgot to ask, have you added the urxvt window class as a terminal in the i3-resurrect config? See https://github.com/JonnyHaystack/i3-resurrect#terminals

Been a while since I've been deep in the code or changed my config so I totally forgot this was a thing.. The terminal emulator's cwd doesn't change, but the shell's cwd does. So you need to add it to that list in the config so that i3-resurrect knows to look at the shell subprocess for the cwd instead of the terminal emulator process.

danhab99 commented 3 years ago

@JonnyHaystack JonnyHaystack

Uh sorry should've asked before but can you also show the output of ls -l /proc/$(xprop _NET_WM_PID | cut -d ' ' -f3)/cwd

lrwxrwxrwx 1 dan dan 0 Sep  8 16:34 /proc/422021/cwd -> /home/dan
JonnyHaystack commented 3 years ago

Did you check that you have done according to my last comment and added it as a terminal? That should fix any problem with working directory being restored. Also I'm not really understanding the problem. Programs running inside your shell aren't normally going to be restored, that's not how it works. If you manually launched the terminal emulator passing in a command to execute directly e.g. if I ran something like alacritty -e tmux a from rofi or from another shell, that would create an alacritty window that launches tmux and attaches to my last session. i3-resurrect can save and restore this no problem because the full command line was passed in from the start, so it's saved in the process cmdline. However, if you start a terminal/shell and later launch another program inside it, e.g. vim, that would not be saved to the cmdline of the shell or terminal emulator so i3-resurrect has no way of knowing to restore it. It's not feasible to look at every subprocess of every subprocess and figure out how to restore everything for arbitrary programs, especially with multi threaded programs etc.

teto commented 3 years ago

Your suggestion solved it for me in kitty. Any reason not to add more terminals to the default list ?

JonnyHaystack commented 3 years ago

@teto I didn't want to go adding things that I haven't tested, but yeah I should really add more