I use the
orphaned
Ion as my window
manager, and I love it. Here’s a Lua script I wrote for Ion
that lets me “pull” a Firefox window to the current frame, parameterized on the
Firefox profile. It finds the pid of the Firefox process by looking at the
~/.mozilla/firefox/[PROFILE]/lock
file, then searches ion for an X window with
that pid in its _NET_WM_PID
X property and attaches it.
pid_atom = ioncore.x_intern_atom('_NET_WM_PID', true)
pull_result = nil
function pull_pid_fn(pid)
return function(window)
local window_pid = ioncore.x_get_window_property(window:xid(), pid_atom, 0, 0, true)
if window_pid and window_pid[1] == pid then
-- have to use this hack because WFrame.attach() can't be called in
-- restricted mode. boo.
pull_result = window
return false
else
return true
end
end
end
function pull_firefox(to, profile)
pull_result = nil
local lock = io.popen("readlink -q ~/.mozilla/firefox/" .. profile .. "/lock"):lines()()
if not lock then
ioncore.warn(profile .. " firefox is not running")
return
end
local pid = string.match(lock, ":%+(%d+)$")
ioncore.clientwin_i(pull_pid_fn(tonumber(pid)))
if pull_result then
to:attach(pull_result, {switchto=true})
else
ioncore.warn("couldn't find " .. profile .. " firefox (pid " .. pid .. ")")
end
end
Wow man I have been struggling to do something like this for a long time. Well a couple of months.
The way I got the id was exactly the same as you! Great minds we both have! :)
But I used lsof to get the pid.
Right now I’m working on trying to focus the most recent window of the PID and then I came across your code. I searched on bing for “firefox _NET_WM_PID”, i wanted to search to see if firefox set the _NET_WM_PID
Hey man do you have any ideas on how to test the “.parentlock” file instead of the “lock” symlink?
New firefoxes use “.parentlock”, they still have “lock” but mac os doesnt have the “lock” so im trying to find a way to detect if firefox is running based on testing “.parentlock” but i cant figure out
Thx man
@Noiitidart interesting! I actually haven’t used this for a while, so you’re ahead of me. sorry I can’t help more. good luck though, and definitely post another comment if you get it working!
Thanks so much man for a reply from such an old post! :)
I think I got it! :)
I’m using fcntl to check if the .parentlock file is locked. Then if fcntl fails, then I fall back and do readlink on the lock file. Then check if the pid in the lock file was last claimed after before the lock file was last modified. (if plug was pulled the lock file persists :( )
Very similar to the checks they make when setting the lock here: http://mxr.mozilla.org/mozilla-release/source/profile/dirserviceprovider/src/nsProfileLock.cpp#289
Right now I’m working on figuring out how to get information on a PID so i can figure out last time it was claimed.
Hey Ryan I got it working! :D I forgot to tell you about it though. So what I do is I test it first with fnctl. That works on macs and linux. Now linux also has that backup lock file, so if fnctl fails on linux then i resort to reading that link file.
Code here: https://github.com/Noitidart/Profilist/blob/e43bc7828346742fad637aafed9e7b41275534c0/modules/workers/ProfilistWorker.js#L219
It uses js-ctypes. :)
@Noitidart oh wow, great find. thanks for letting me know!