Skip to content

Commit

Permalink
Add basic settings
Browse files Browse the repository at this point in the history
Fixes #4
  • Loading branch information
p-e-w committed Apr 29, 2017
1 parent 888abe2 commit 04f7876
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ vala_precompile(VALA_C ${LIB_NAME}
src/Command.vala
src/CommandExtractor.vala
src/CommandList.vala
src/InstanceSettings.vala
src/Keybinder.vala
src/Module.vala
src/PopupWindow.vala
src/Utilities.vala
PACKAGES
gtk+-3.0>=3.16
posix
)

include(GSettings)
add_schema(data/com.worldwidemann.plotinus.gschema.xml)

add_library(${LIB_NAME} SHARED ${VALA_C})
install(TARGETS ${LIB_NAME} LIBRARY DESTINATION lib)
37 changes: 34 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Have you used Sublime Text's or Atom's "Command Palette"? It's a list of everyth

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!

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.
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.

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

Expand Down Expand Up @@ -49,17 +49,24 @@ mkdir build
cd build
cmake ..
make
sudo make install
```

### Enabling Plotinus in applications

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
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

```
GTK3_MODULES=[libpath]
```

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
to `/etc/environment`, where `[libpath]` is the *full, absolute* path of `libplotinus.so`, which can be found using the command

```
whereis -b libplotinus
```

Alternatively, you can try Plotinus with individual applications by running them with

```
GTK3_MODULES=[libpath] application
Expand All @@ -68,6 +75,30 @@ GTK3_MODULES=[libpath] application
from a terminal.


## Configuration

Plotinus can be configured both globally and per application. Application settings take precedence over global settings. In the commands below, `[application]` can be either

* `default`, in which case the setting is applied globally, or
* 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`).

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`.

### Enabling/disabling Plotinus

```
gsettings set com.worldwidemann.plotinus:/com/worldwidemann/plotinus/[application]/ enabled [true/false]
```

### Changing the keyboard shortcut

```
gsettings set com.worldwidemann.plotinus:/com/worldwidemann/plotinus/[application]/ hotkeys '[keys]'
```

`[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.


## Acknowledgments

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.
Expand Down
14 changes: 14 additions & 0 deletions data/com.worldwidemann.plotinus.gschema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
<schema id="com.worldwidemann.plotinus">

<key name="enabled" type="b">
<default>true</default>
</key>

<key name="hotkeys" type="as">
<default><![CDATA[ ["<Primary><Shift>P"] ]]></default>
</key>

</schema>
</schemalist>
34 changes: 34 additions & 0 deletions src/InstanceSettings.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Plotinus - A searchable command palette in every modern GTK+ application
*
* Copyright (c) 2016-2017 Philipp Emanuel Weidmann <[email protected]>
*
* Nemo vir est qui mundum non reddat meliorem.
*
* Released under the terms of the GNU General Public License, version 3
* (https://gnu.org/licenses/gpl.html)
*/

class Plotinus.InstanceSettings : Object {

private Settings base_settings;
private Settings instance_settings;

public InstanceSettings(string schema_id, string base_name, string instance_name) {
var schema_path = "/" + schema_id.replace(".", "/") + "/";

base_settings = new Settings.with_path(schema_id, schema_path + base_name + "/");
instance_settings = new Settings.with_path(schema_id, schema_path + instance_name + "/");
}

// Returns the value from instance_settings if it has been set there
// and falls back to base_settings otherwise
public Variant get_value(string key) {
if (instance_settings.get_user_value(key) != null) {
return instance_settings.get_value(key);
} else {
return base_settings.get_value(key);
}
}

}
13 changes: 10 additions & 3 deletions src/Module.vala
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ namespace Plotinus {

const uint SCAN_INTERVAL = 100;

const string[] HOTKEYS = { "<Primary><Shift>P" };

// Method signature adapted from https://github.com/gnome-globalmenu/gnome-globalmenu
[CCode(cname="gtk_module_init")]
public void gtk_module_init([CCode(array_length_pos=0.9)] ref unowned string[] argv) {
Gtk.init(ref argv);

// See http://stackoverflow.com/a/606057
var executable_path = FileUtils.read_link("/proc/%u/exe".printf(Posix.getpid()));

var instance_name = executable_path.substring(1).replace("/", ".");
var settings = new InstanceSettings("com.worldwidemann.plotinus", "default", instance_name);

if (!settings.get_value("enabled").get_boolean())
return;

Timeout.add(SCAN_INTERVAL, () => {
Keybinder? keybinder = null;
CommandExtractor? command_extractor = null;
Expand Down Expand Up @@ -66,7 +73,7 @@ namespace Plotinus {
}
});

keybinder.set_keys(HOTKEYS);
keybinder.set_keys(settings.get_value("hotkeys").dup_strv());

return false;
}
Expand Down

0 comments on commit 04f7876

Please sign in to comment.