i3: Starting mpv from ranger on different workspace - i3

I would like to configure my i3wm and ranger file manager in such a way that when I choose a movie in ranger, it opens video in mpv on workspace 10 in fullscreen. The problem is that everything works fine without --fs (fullscreen option on mpv), but when I add the --fs flag, i3 doesn't move mpv to workspace 10 and it opens wherever ranger is.
In .i3/config:
assign [class="mpv"] $ws10
In .config/ranger/rifle.conf:
mime ^video|audio, has mpv, X, flag f = mpv --fs -- "$#"
Why is fullscreen so problematic? Is there any solution to this?

I applied your settings: assign [class="mpv"] $ws10 and mime ^video|audio, has mpv, X, flag f = mpv --fs -- "$#". When I open a video file in ranger, mpv opens video in fullscreen mode in ws10. Actually, your settings work well on my machine :)
Since --fs is the problem for you, I would suggest to remove --fs in .config/ranger/rifle.conf:
mime ^video|audio, has mpv, X, flag f = mpv -- "$#"
And then, use fullscreen mode from i3wm:
assign [class="mpv"] $ws10
for_window [class="mpv"] fullscreen
Hope this alternative could solve your problem.

Related

How to automatically start programs in a specific order?

I have these lines in my i3 configuration file:
# Startup applications.
exec firefox
exec gnome-terminal
exec nautilus
These lines start firefox, gnome-terminal and nautilus as expected, but the order in which they start is unpredictable. Is there a way to start these applications in a way that makes the windows appear in the order that I want? (i.e. firefox, then gnome-terminal, then nautilus).
Refer to Layout saving in i3.
Add this to the i3 configuration file:
# Create specific layout for applications.
exec --no-startup-id "i3-msg 'workspace 1; append_layout ~/.config/i3/workspace-1.json'"
# Start applications.
exec firefox
exec gnome-terminal
Create ~/.config/i3/workspace-1.json:
// Layout of a workspace.
{
"layout": "tabbed",
// To get a window's class name, run xprop and click on the window.
// You will see the following output:
// WM_CLASS(STRING) = "InstanceName", "ClassName"
// Alternatively, "swallow" by the window's title.
"nodes": [
{"swallows": [{"class": "^Firefox$"}]},
{"swallows": [{"class": "^Gnome-terminal$"}]}
]
}
You can save layouts so that each application is captured by a predefined window container. Making it truly automatic requires a little extra scripting. Examples from my configuration:
i3 config
assign [class="^Vivaldi-stable$"] 1
assign [class="^Keepassx2$"] 2
assign [class="^Thunderbird$"] 2
....
# last line
exec ~/.config/i3/restore.sh &
restore.sh
#!/bin/sh
for layout in ~/.config/i3/layouts/*; do
i3-msg "workspace $(basename "$layout" .json); append_layout $layout"
done
(vivaldi-stable &)
(keepassxc &)
(thunderbird &)
If you want to see the full version, my dotfiles are on GitHub.

Use backtick/Grave/Tilde as modifier key

I'm looking for a way to create keyboard shortcuts in Linux using backtick (`) / tilde (~) key and some other key. In an ideal case:
pressing tilde down does nothing
pressing another key while the tilde is pressed down triggers a (customizable) shortcut
when releasing the tilde before/without pressing another key, just send the tilde keystroke.
I have something similar in AutoHotKey for Windows, and i've been searching for a way to recreate this in a (any) Linux environment. I would consider using any GUI if i could get this working, but of course a more "general" solution would be even better.
I think i finally got it!!
I use xmodmap to turn the grave key into the modifier Hyper_L, and XCape to send the grave if the key is released without another key being pressed.
Xcape was intended to open the app menu ("Start menu") when the meta-key ("windows key") is pressed and released without another key, so as an added bonus, it does that too. Meaning you can both use Meta as a modifier, like Meta-F to open the file manager AND use the meta-key seperately to open the whiskers menu.
If all is right, you can open the keyboard settings manager using ~-k, and you can make new shortcuts using the ~-key. Because that's still tiresome and not easily portable between different systems, i've included some shortcuts using xfconf-query, which will probably only work in Xfce.
Here's the basics of my script:
#!/bin/sh
# reset pretty much ALL keyboard settings
setxkbmap
# Free up the mod3 and mod4 flags from all keys it may be associated with:
xmodmap -e "clear mod3"
xmodmap -e "clear mod4"
# Add Hyper_L to the grave key (49)
xmodmap -e "keycode 49 = Hyper_L asciitilde grave asciitilde"
# You need a grave key somewhere else (!) so, bind it to an unused key:
xmodmap -e "keycode 250 = grave"
# Restore Mod4 but without Hyper_L (which was at location 4)
xmodmap -e "add mod4 = Super_L Super_R Super_L"
# Assign the mod3 to Hyper_L:
xmodmap -e "add mod3 = Hyper_L"
dist=100
/usr/bin/xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/\<Hyper\>Right -s "xdotool mousemove_relative -- $dist 0" --create -t string
/usr/bin/xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/\<Hyper\>Down -s "xdotool mousemove_relative -- 0 $dist" --create -t string
/usr/bin/xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/\<Hyper\>Left -s "xdotool mousemove_relative -- -$dist 0" --create -t string
/usr/bin/xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/\<Hyper\>Up -s "xdotool mousemove_relative -- 0 -$dist" --create -t string
/usr/bin/xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/\<Hyper\>space -s "xdotool click 1" --create -t string
/usr/bin/xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/\<Hyper\>k -s "xfce4-keyboard-settings" --create -t string
# (re)starting xcape to produce a ` after key-up if no other key was pressed
killall xcape
xcape -t5000 -e "#49=grave;Super_L=Control_L|Escape" &
A more extended version of the script, with some more shortcuts can be found here.
I am not sure if it will work out for you but you should check:
xdotool (http://manpages.ubuntu.com/manpages/precise/man1/xdotool.1.html)
zenity (http://manpages.ubuntu.com/manpages/precise/man1/zenity.1.html)
Both these tools let you create some custom actions and shortcuts.
Here is an example of xdotool: https://askubuntu.com/questions/212154/create-a-custom-shortcut-that-types-clipboard-contents
Hope it helps and good luck :)
Bruno
After switching to Ubuntu on another machine, I also wanted to use tilde as a modifier key the way I use it in my AHK scripts.
I did quite some research on different tools for ex. xdotool, xev, autotools, xbindkeys and so on and finally found a solution to that. Here are the steps.
Install Autokey, python, python evded module, xte(sudo apt-get install xautomation).
Read a little about Autokey and how it launches python scripts or create hotstrings. In Autokey, we can set a hotkey to call a python script. So you can assign the python script down below to your tilde key or for that matter whatever custom hotkey you plan to create.
Here is the required custom functionality(thought not yet completely ported to linux, I have it scripted in autohotkey and just love it. It keeps the hand glued to keyboard ;))
Tilde + Up arrow: Move mouse pointer upwards by 100 positions
Tilde + Down arrow: Move mouse pointer downwards by 100 positions
Tilde + Right arrow: Move mouse pointer to right by 100 positions
Tilde + Left arrow: Move mouse pointer to left by 100 positions
Tilde + Enter: Left Mouse click (not present in the python script)
Tilde + Alt + Enter: Right Mouse Click
I use the tilde (KEY_GRAVE) as my modifier key. When this key is pressed, Autokey launches the python script. The scripts runs a loop until the tilde key is released. In the loop, the script keeps on detecting the keyboard inputs. On a UP arrow key(KEY_UP) press, the script sends a command to move a mouse by relative position (0, -100) utilizing 'xte' and so on.
from evdev import InputDevice, categorize, ecodes
from select import select
dev = InputDevice('/dev/input/event4')
releasekey = False
while releasekey==False:
r,w,x = select([dev], [], [])
for event in dev.read():
if event.type == ecodes.EV_KEY:
#system.exec_command("xte 'mousermove 0 3'", False)
#break
if event.code == ecodes.KEY_UP:
if event.value == 1:
system.exec_command("xte 'mousermove 0 -100'", False)
if event.code == ecodes.KEY_DOWN:
if event.value == 1:
system.exec_command("xte 'mousermove 0 100'", False)
if event.code == ecodes.KEY_RIGHT:
if event.value == 1:
system.exec_command("xte 'mousermove 100 0'", False)
if event.code == ecodes.KEY_LEFT:
if event.value == 1:
system.exec_command("xte 'mousermove -100 0'", False)
if event.code == ecodes.KEY_GRAVE:
if event.value == 0:
releasekey = True
break
You have to adjust the dev = InputDevice('/dev/input/event4') line to assign the correct name of your keyboard. In my case, event4 is my keyboard. Yours might be different. You can check out the handy tutorial "Reading Events" on python-evdev. That code actually outputs the name of your keyboard listed under /dev/input. Actually, my script is an extention to that tutorial script.
The only problem is that the python script must be started as a root user otherwise the keyboard input device can not be accessed. You can overcome this by creating a udev rule file which changes the permission of the device to make it available for reading writing eg. create a rule file and add this line
KERNEL=='event4', MODE="0660" and load the rule . At the end you must add yourself in the GROUP which have read/write permission for the device. The information regarding file permission can be found using ls -la in the /dev/input folder.
I hope it works for you. In it doesn´t work at first go, then get a cup of coffee and fight on till it works ;)

Create window into screen

Is there a way to list all window names and depending on the result, creating a new window with a specific name into this (running) session.
How to create a new screen session with assigned window names is documented in the man pages, but i could find information about a solution to the problem above.
From outside the screen session, I don't think so.
But if you are starting from inside, in one of the windows of the right screen session, then yes:
for window_name in foo bar baz quux ; do ## ...
screen -t $window_name
done
You can even get fancy and run some initial commands in each window! This snipped of copy-paste bash helps me get back to work quickly after a reboot. Once I've started the screen session:
for n in $(seq 1 8) ; do ## ...
screen -t proj_$n bash -c "cd /src/foo/proj_$n*/ ;"\
' eval `set_proj_env_vars.sh` ; svn status ; make clean ; make ;'\
' exec bash --login'
done
...and as a great side effect the screen windows are numbered for the various checkouts, where each one can be working on a different bug/feature. Overkill? Totally! But it's a fun hack.

How to set emacsclient background as Emacs background?

I've got (in my .emacs)
(set-background-color "#101416")
(set-foreground-color "#f6f3e8")
And I've got 2 bindings:
alias ex='emacsclient -nw'
alias ec='emacsclient -c -a ""'
ex works fine to open client in terminal but when I want to open it as a frame I've got white background :(
Why and how can I use my dark background there?
set-background-color and set-foreground-color only affect the current frame, and your .emacs file is not executed when running emacsclient.
Try setting the variable default-frame-alist ("Alist of default values for frame creation") instead:
(setq default-frame-alist
'((background-color . "#101416")
(foreground-color . "#f6f3e8")))

using the -W option of vim

the -w and -W options of vim have theoretically the following effect:
-w {scriptout} All the characters that you type are recorded in the file
"scriptout", until you exit Vim.
This is useful if you want to create
a script file to be used with "vim -s"
or ":source!". When the "scriptout"
file already exists, new characters
are appended. See also
|complex-repeat|. {scriptout} cannot
start with a digit. {not in Vi}
-W {scriptout} Like -w, but do not append, overwrite an existing file.
{not in Vi}
But when I do this, the {scriptout} file will always begin with a hexadecimal sequence like 80 fd 60 (sometimes it is 80 fd 62).
I am using gvimportable.exe 7.3 from portableapps.com. With the -u NONE switch, it does the same.
What is this “magic number” for? Under Windows with gvim.exe I cannot replay my scriptout until I have removed those three leading bytes…
It seems that this feature, which could be very useful, is poorly documented.
Thank you for your answers.
(This answer is probably fragmented significantly, it took me a while playing around - I wanted to find a solution too because it intrigued me - not just the bounty of 200 :P. It more or less shows my train of thought and experimentation.)
I can now reproduce it with gvim on Linux, which is /usr/bin/vim.gnome -g; running as vim -g does just the same.
Delving into the code: (futile in this case, but fun to do and to learn how to do)
I've looked through the source code and I can now explain it somewhat (but not usefully!); it gets the outfile FILE (src/globals.h:1004) set (src/main.h:2275); this is then written to in src/getchar.h:1501, in the updatescript method which is used by gotchars (line 1215) which is used by vgetorpeek, which is used by vgetc and vpeekc... (no, I don't know where this is going!) then these are used in a number of places.
Anyway, I suppose the key is somewhere in src/gui.c, but I don't know where at the moment! It's also possible that some key sequence is being "sent" (physically or virtually, I don't know), but seeing as the issue is the same across platforms it would seem more likely to be a Vim issue than otherwise.
Interesting situations leading to a probable explanation:
It's also worth while noting that if you automatically quit, gvim -u NONE -w scriptout -c quit (:quit after loading) or gvim -u NONE -w scriptout -c quit (instant :quit, never shows GUI), the file scriptout is left empty.
Additionally, if you open gvim and then close it using the X button, pressing no keys:
0000000: 80fd 6280 fd63 80fd 62 ..b..c..b
If you open gvim, click away, click back and use :q:
0000000: 80fd 6280 fd63 80fd 6280 fd2c 80fd 2e3a ..b..c..b..,...:
0000010: 710d q.
So I think it's the window events are internally translated into something else. 80 fd 62 is the open sequence and 80 fd 63 80 fd 62 is the close sequence.
I've found another way of triggering 80fd as well, which leads me to thing it's some sort of "user has access to the window"; by default with GNOME in Ubuntu, Ctrl+Alt+S does something with the window (can't remember what it's called; slides it all up into the title bar, app inside loses keyboard control etc.). gvim ... (you know the arguments!), i<Ctrl+Alt+S (contracted) Ctrl+Alt+S (expanded) >Esc Z Q produces this for me:
0000000: 80fd 6269 3c80 fd63 80fd 623e 1b5a 51 ..bi<..c..b>.ZQ
Summary: so there we have what I believe is the solution; gVim catches the window messages in some form and - whether it should or shouldn't - puts them in its scriptout. If you think it shouldn't (or would like to know why they're left in or if they're even meant to be or whether you should care at all), ask on the Vim list, I think.
My best guess is that this is a bug in the GUI code of gVim.
Using gVim 7.3, if I run gvim -u NONE -W scriptout then I see the problem, but if I run vim -u NONE -W scriptout then the unwanted bytes are not present.
I also tested Vim 7.2 from the shell in Linux, the version of Vim included in Snow Leopard (7.2), and the GUI and terminal versions of MacVim 7.2 (with mvim -W and /Applications/MacVim/Contents/MacOS/Vim -W, respectively) and they all worked correctly.
Someone has done the hard work for us in the vimgolf project, in particular this well-commented file: https://github.com/igrigorik/vimgolf/blob/master/lib/vimgolf/lib/vimgolf/keylog.rb
0x80 in escape sequence for special two-byte codes. In this case they represent gvim focus events. See here:
# If you use gvim, you'll get an entry in your keylog every time the
# window gains or loses focus. These "keystrokes" should not show and
# should not be counted.
"\xfd\x60" => nil, # 7.2 Focus Gained compat
"\xfd\x61" => nil, # Focus Gained (GVIM) (>7.4.1433)
"\xfd\x62" => nil, # Focus Gained (GVIM)
"\xfd\x63" => nil, # Focus Lost (GVIM)

Resources