Skip to content

Commit

Permalink
Add command line flag to directly open in color picker mode
Browse files Browse the repository at this point in the history
Add the command line flag `--pick-color` to open the
application directly in color picking mode. This could
be helpful in setting up keybindings.

Add documentation for the option.
  • Loading branch information
adithyankv committed Jul 1, 2022
1 parent b4ec6e2 commit 8d28767
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ flatpak install https://flatpak.elementary.io/repo/appstream/com.github.phoneyba
Flatpak is the recommended method of installation, however if you don't want
to use flatpak you can always build from source using the build instructions.

## Usage
If installed as flatpak the program can be launched using
```
flatpak run com.github.phoneybadger.picker
```
the app can be launched directly in color picking mode using the command line
option `--pick-color`. This could be perhaps be used to set up a keybinding.
```
flatpak run com.github.phoneybadger.picker --pick-color
```
and the program should also be visible in your launcher/application menu

## Building and running
Download or clone the repo
```
Expand All @@ -48,7 +60,6 @@ the program should now be installed and can be run using
```
flatpak run com.github.phoneybadger.trimmer
```
it should also be visible in your launcher/application menu.

### Without flatpak

Expand Down
23 changes: 22 additions & 1 deletion src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ namespace Picker {
{ACTION_START_PICK, action_start_pick}
};

private const OptionEntry[] CMD_OPTION_ENTRIES = {
{"pick-color", 'p', OptionFlags.NONE, OptionArg.NONE, null, N_("Pick color"), null}
};

public Application () {
Object (
application_id: "com.github.phoneybadger.picker",
flags: ApplicationFlags.FLAGS_NONE
flags: ApplicationFlags.HANDLES_COMMAND_LINE
);
}

construct {
add_main_option_entries (CMD_OPTION_ENTRIES);
}

public override void activate () {
set_prefered_color_scheme ();
add_action_entries (ACTION_ENTRIES, this);
Expand All @@ -37,6 +45,19 @@ namespace Picker {
}
}

public override int command_line (ApplicationCommandLine command) {
activate ();

/* Opens and immediately starts picking color if the --pick-color
flag is passed when launching from the command line. This could
be helpful for the user to set up keybindings and stuff */
var options = command.get_options_dict ();
if (options.contains ("pick-color")) {
lookup_action (ACTION_START_PICK).activate (null);
}
return 0;
}

private void action_start_pick () {
window.color_picker.start_picking ();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Main.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
public int main (string[] args) {
var picker = new Picker.Application ();
int status = picker.run ();
int status = picker.run (args);

return status;
}

0 comments on commit 8d28767

Please sign in to comment.