Skip to content

Commit 04f7876

Browse files
committed
Add basic settings
Fixes #4
1 parent 888abe2 commit 04f7876

File tree

5 files changed

+98
-6
lines changed

5 files changed

+98
-6
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@ vala_precompile(VALA_C ${LIB_NAME}
2424
src/Command.vala
2525
src/CommandExtractor.vala
2626
src/CommandList.vala
27+
src/InstanceSettings.vala
2728
src/Keybinder.vala
2829
src/Module.vala
2930
src/PopupWindow.vala
3031
src/Utilities.vala
3132
PACKAGES
3233
gtk+-3.0>=3.16
34+
posix
3335
)
3436

37+
include(GSettings)
38+
add_schema(data/com.worldwidemann.plotinus.gschema.xml)
39+
3540
add_library(${LIB_NAME} SHARED ${VALA_C})
41+
install(TARGETS ${LIB_NAME} LIBRARY DESTINATION lib)

README.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Have you used Sublime Text's or Atom's "Command Palette"? It's a list of everyth
1515

1616
Plotinus brings that power ***to every application on your system*** (that is, to those that use the GTK+ 3 toolkit). It automatically extracts all available commands by introspecting a running application, instantly adapting to UI changes and showing only relevant actions. Using Plotinus requires *no modifications* to the application itself!
1717

18-
Just press <kbd>Ctrl+Shift+P</kbd> and you're in business – it feels so natural you'll soon wonder how you ever lived without it.
18+
Just press <kbd>Ctrl+Shift+P</kbd> ([configurable](#configuration)) and you're in business – it feels so natural you'll soon wonder how you ever lived without it.
1919

2020
![Nautilus screencast](https://cloud.githubusercontent.com/assets/2702526/20246717/454a1a9a-a9e3-11e6-8b19-4db092348793.gif)
2121

@@ -49,17 +49,24 @@ mkdir build
4949
cd build
5050
cmake ..
5151
make
52+
sudo make install
5253
```
5354

5455
### Enabling Plotinus in applications
5556

56-
Because of the complexity and clumsiness surrounding Linux environment variables, Plotinus does not currently install automatically. The easiest way to enable Plotinus for all applications is to add the line
57+
Because of the complexity and clumsiness surrounding Linux environment variables, Plotinus is currently not enabled automatically. The easiest way to enable Plotinus for all applications on the system is to add the line
5758

5859
```
5960
GTK3_MODULES=[libpath]
6061
```
6162

62-
to `/etc/environment`, where `[libpath]` is the *full, absolute* path of `libplotinus.so` as built by `make`. Alternatively, you can try individual applications with Plotinus by running them with
63+
to `/etc/environment`, where `[libpath]` is the *full, absolute* path of `libplotinus.so`, which can be found using the command
64+
65+
```
66+
whereis -b libplotinus
67+
```
68+
69+
Alternatively, you can try Plotinus with individual applications by running them with
6370

6471
```
6572
GTK3_MODULES=[libpath] application
@@ -68,6 +75,30 @@ GTK3_MODULES=[libpath] application
6875
from a terminal.
6976

7077

78+
## Configuration
79+
80+
Plotinus can be configured both globally and per application. Application settings take precedence over global settings. In the commands below, `[application]` can be either
81+
82+
* `default`, in which case the setting is applied globally, or
83+
* the path of an application executable, without the leading slash and with all other slashes replaced by periods (e.g. `/usr/bin/gedit` -> `usr.bin.gedit`).
84+
85+
Note that the relevant path is the path of the *process executable*, which is not always identical to the executable being launched. For example, all GNOME JavaScript applications run the process `/usr/bin/gjs`.
86+
87+
### Enabling/disabling Plotinus
88+
89+
```
90+
gsettings set com.worldwidemann.plotinus:/com/worldwidemann/plotinus/[application]/ enabled [true/false]
91+
```
92+
93+
### Changing the keyboard shortcut
94+
95+
```
96+
gsettings set com.worldwidemann.plotinus:/com/worldwidemann/plotinus/[application]/ hotkeys '[keys]'
97+
```
98+
99+
`[keys]` must be an array of strings in the format expected by [`gtk_accelerator_parse`](https://developer.gnome.org/gtk3/stable/gtk3-Keyboard-Accelerators.html#gtk-accelerator-parse), e.g. `["<Primary><Shift>P", "<Primary>P"]`. Each shortcut in the array activates Plotinus.
100+
101+
71102
## Acknowledgments
72103

73104
Documentation on GTK+ modules is essentially nonexisting. Without [gtkparasite](https://github.com/chipx86/gtkparasite) and [gnome-globalmenu](https://github.com/gnome-globalmenu/gnome-globalmenu) to learn from, it would have been a lot harder to get this project off the ground.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<schemalist>
3+
<schema id="com.worldwidemann.plotinus">
4+
5+
<key name="enabled" type="b">
6+
<default>true</default>
7+
</key>
8+
9+
<key name="hotkeys" type="as">
10+
<default><![CDATA[ ["<Primary><Shift>P"] ]]></default>
11+
</key>
12+
13+
</schema>
14+
</schemalist>

src/InstanceSettings.vala

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Plotinus - A searchable command palette in every modern GTK+ application
3+
*
4+
* Copyright (c) 2016-2017 Philipp Emanuel Weidmann <[email protected]>
5+
*
6+
* Nemo vir est qui mundum non reddat meliorem.
7+
*
8+
* Released under the terms of the GNU General Public License, version 3
9+
* (https://gnu.org/licenses/gpl.html)
10+
*/
11+
12+
class Plotinus.InstanceSettings : Object {
13+
14+
private Settings base_settings;
15+
private Settings instance_settings;
16+
17+
public InstanceSettings(string schema_id, string base_name, string instance_name) {
18+
var schema_path = "/" + schema_id.replace(".", "/") + "/";
19+
20+
base_settings = new Settings.with_path(schema_id, schema_path + base_name + "/");
21+
instance_settings = new Settings.with_path(schema_id, schema_path + instance_name + "/");
22+
}
23+
24+
// Returns the value from instance_settings if it has been set there
25+
// and falls back to base_settings otherwise
26+
public Variant get_value(string key) {
27+
if (instance_settings.get_user_value(key) != null) {
28+
return instance_settings.get_value(key);
29+
} else {
30+
return base_settings.get_value(key);
31+
}
32+
}
33+
34+
}

src/Module.vala

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@ namespace Plotinus {
1515

1616
const uint SCAN_INTERVAL = 100;
1717

18-
const string[] HOTKEYS = { "<Primary><Shift>P" };
19-
2018
// Method signature adapted from https://github.com/gnome-globalmenu/gnome-globalmenu
2119
[CCode(cname="gtk_module_init")]
2220
public void gtk_module_init([CCode(array_length_pos=0.9)] ref unowned string[] argv) {
2321
Gtk.init(ref argv);
2422

23+
// See http://stackoverflow.com/a/606057
24+
var executable_path = FileUtils.read_link("/proc/%u/exe".printf(Posix.getpid()));
25+
26+
var instance_name = executable_path.substring(1).replace("/", ".");
27+
var settings = new InstanceSettings("com.worldwidemann.plotinus", "default", instance_name);
28+
29+
if (!settings.get_value("enabled").get_boolean())
30+
return;
31+
2532
Timeout.add(SCAN_INTERVAL, () => {
2633
Keybinder? keybinder = null;
2734
CommandExtractor? command_extractor = null;
@@ -66,7 +73,7 @@ namespace Plotinus {
6673
}
6774
});
6875

69-
keybinder.set_keys(HOTKEYS);
76+
keybinder.set_keys(settings.get_value("hotkeys").dup_strv());
7077

7178
return false;
7279
}

0 commit comments

Comments
 (0)