Added hyprpicker

This commit is contained in:
Charadon 2024-01-29 18:31:13 +00:00
parent 8cf0c011af
commit bda1d8fd13
9 changed files with 152 additions and 39 deletions

3
.gitmodules vendored
View File

@ -16,3 +16,6 @@
[submodule "subprojects/xdg-desktop-portal-wlr"]
path = subprojects/xdg-desktop-portal-wlr
url = https://github.com/emersion/xdg-desktop-portal-wlr
[submodule "subprojects/hyprpicker"]
path = subprojects/hyprpicker
url = https://github.com/hyprwm/hyprpicker

View File

@ -134,15 +134,18 @@ static const enum libinput_config_tap_button_map button_map = LIBINPUT_CONFIG_TA
/* helper for spawning shell commands in the pre dwm-5.0 fashion */
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
#define APP_LAUNCHER "wofi -l top -D drun-display_generic=true -H 200 -W 1920 -G -o DP-1 -m -I -S drun"
/* commands */
static const Key keys[] = {
/* Note that Shift changes certain key codes: c -> C, 2 -> at, etc. */
/* modifier key function argument */
{ MODKEY, XKB_KEY_r, spawn, SHCMD("wofi -l top -H 200 -W 1920 -G -o DP-1 -m -I -S drun") },
{ MODKEY, XKB_KEY_r, spawn, SHCMD(APP_LAUNCHER) },
{ 0, XF86XK_AudioRaiseVolume, spawn, SHCMD("pamixer --allow-boost -i 10 && ogg123 /usr/share/sounds/freedesktop/stereo/audio-volume-change.oga")},
{ 0, XF86XK_AudioLowerVolume, spawn, SHCMD("pamixer --allow-boost -d 10 && ogg123 /usr/share/sounds/freedesktop/stereo/audio-volume-change.oga")},
{ 0, XKB_KEY_Print, spawn, SHCMD("org.flameshot.Flameshot gui --raw | wl-copy") },
{ WLR_MODIFIER_SHIFT, XKB_KEY_Print, spawn, SHCMD("hyprpicker | wl-copy")},
{ 0, XKB_KEY_XF86AudioPlay, spawn, SHCMD("playerctl-toggle.pl") },
{ 0, XKB_KEY_XF86AudioNext, spawn, SHCMD("playerctl -p pragha next") },
{ 0, XKB_KEY_XF86AudioPrev, spawn, SHCMD("playerctl -p pragha previous") },
@ -195,20 +198,36 @@ static const Key keys[] = {
CHVT(1), CHVT(2), CHVT(3), CHVT(4), CHVT(5), CHVT(6),
CHVT(7), CHVT(8), CHVT(9), CHVT(10), CHVT(11), CHVT(12),
};
#define WEB_BROWSER "firefox"
#define TERMINAL "terminator"
#define FILE_MANAGER "thunar"
#define TASK_MANAGER "qps"
#define CALCULATOR "kcalc"
/* mode modifier key function argument */
static const Modekey modekeys[] = {
{ QUICK_LAUNCH, { 0, XKB_KEY_f, spawn, SHCMD("firefox") } },
{ QUICK_LAUNCH, { 0, XKB_KEY_f, entermode, {.i = NORMAL} } },
{ QUICK_LAUNCH, { 0, XKB_KEY_t, spawn, SHCMD("terminator") } },
/* Quick Launch */
{ QUICK_LAUNCH, { 0, XKB_KEY_w, spawn, SHCMD(WEB_BROWSER) } },
{ QUICK_LAUNCH, { 0, XKB_KEY_w, entermode, {.i = NORMAL} } },
{ QUICK_LAUNCH, { 0, XKB_KEY_t, spawn, SHCMD(TERMINAL) } },
{ QUICK_LAUNCH, { 0, XKB_KEY_t, entermode, {.i = NORMAL} } },
{ QUICK_LAUNCH, { 0, XKB_KEY_g, spawn, SHCMD("guake-toggle") } },
{ QUICK_LAUNCH, { 0, XKB_KEY_g, entermode, {.i = NORMAL} } },
{ QUICK_LAUNCH, { 0, XKB_KEY_f, spawn, SHCMD(FILE_MANAGER) } },
{ QUICK_LAUNCH, { 0, XKB_KEY_f, entermode, {.i = NORMAL} } },
{ QUICK_LAUNCH, { 0, XKB_KEY_s, spawn, SHCMD(TASK_MANAGER) } },
{ QUICK_LAUNCH, { 0, XKB_KEY_s, entermode, {.i = NORMAL} } },
{ QUICK_LAUNCH, { 0, XKB_KEY_c, spawn, SHCMD(CALCULATOR) } },
{ QUICK_LAUNCH, { 0, XKB_KEY_c, entermode, {.i = NORMAL} } },
{ QUICK_LAUNCH, { 0, XKB_KEY_Escape, spawn, {.i = NORMAL} } },
/* Power Mode */
{ POWER_MODE, { 0, XKB_KEY_Pause, spawn, SHCMD("loginctl suspend") } },
{ POWER_MODE, { 0, XKB_KEY_Pause, entermode, {.i = NORMAL} } },
{ POWER_MODE, { 0, XKB_KEY_Page_Down, spawn, SHCMD("loginctl reboot") } },
{ POWER_MODE, { 0, XKB_KEY_Page_Down, entermode, {.i = NORMAL} } },
{ POWER_MODE, { 0, XKB_KEY_Delete, spawn, SHCMD("loginctl poweroff") } },
{ POWER_MODE, { 0, XKB_KEY_Delete, entermode, {.i = NORMAL} } },
{ POWER_MODE, { 0, XKB_KEY_Escape, spawn, {.i = NORMAL} } },
};

View File

@ -13,19 +13,20 @@ message('Finding programs for desktop environment. They aren\'t neccesary to use
find_program('pipewire', required: false)
find_program('pipewire-pulse', required: false)
find_program('wireplumber', required: false)
find_program('swaync', required: false)
find_program('keepassxc', required: false)
find_program('akregator', required: false)
find_program('thunderbird', required: false)
find_program('firefox', required: false)
find_program('pragha', required: false)
find_program('q4wine', required: false)
# Flatpak version
find_program('ua.org.brezblock.q4wine', required: false)
find_program('ua.org.brezblock.q4wine', required: false)
find_program('flameshot', required: false)
# Flatpak version
find_program('org.flameshot.Flameshot', required: false)
# Portals
find_program('/usr/libexec/xdg-desktop-portal-wlr', required: false)
find_program('/usr/lib64/libexec/xdg-desktop-portal-kde', required: false)
@ -46,6 +47,16 @@ pamixer_sub = subproject('pamixer')
swaybg_sub = subproject('swaybg')
portal_sub = subproject('xdg-desktop-portal-wlr')
# Hyprpicker
meson.add_postconf_script('scripts/build-hyprpicker.pl')
dependency('wayland-client', required: true)
dependency('wayland-protocols', required: true)
dependency('xkbcommon', required: true)
dependency('cairo', required: true)
dependency('pango', required: true)
dependency('pangocairo', required: true)
dependency('libjpeg', required: true)
deps = [
dependency('wayland-scanner'),
dependency('wayland-protocols'),

41
scripts/build-hyprpicker.pl Executable file
View File

@ -0,0 +1,41 @@
#!/usr/bin/env perl
use strict;
use warnings FATAL => 'all';
use English;
use Cwd qw(abs_path);
use File::Copy qw(cp);
use File::Path qw(make_path);
sub run_cmd {
my $cmd = $ARG[0];
system($cmd);
my $rv = ($CHILD_ERROR >> 8); # Get return code.
if($rv != 0) {
return(0);
}
return(1);
}
my $MESON_BUILD_ROOT = $ENV{MESON_BUILD_ROOT} // die("Couldn't get environment variable: MESON_BUILD_ROOT");
my $MESON_SOURCE_ROOT = $ENV{MESON_SOURCE_ROOT} // die("Couldn't get environment variable: MESON_SOURCE_ROOT");
# Copy hyprpicker subproject to build root.
# We use the system `cp` command because there's no recursive copy function in the
# perl core modules. It's not that big of a deal anyways.
if(!run_cmd("cp -r $MESON_SOURCE_ROOT/subprojects/hyprpicker $MESON_BUILD_ROOT/")) {
die("Failed to copy hyprpicker subproject.");
}
# Build Hyprpicker
chdir("$MESON_BUILD_ROOT/hyprpicker") or die($ERRNO);
if(!run_cmd("make")) {
# Try gmake
if(!run_cmd("gmake")) {
die("Couldn't build hyprpicker.");
}
}
# Copy the finished build into subprojects folder.
make_path("$MESON_BUILD_ROOT/subprojects/hyprpicker") or die($ERRNO);
cp("build/hyprpicker", "$MESON_BUILD_ROOT/subprojects/hyprpicker/hyprpicker") or die($ERRNO);
exit(0);

View File

@ -64,6 +64,7 @@ link_sub_binary("wofi");
link_sub_binary("dwlmsg");
link_sub_binary("wev");
link_sub_binary("pamixer");
link_sub_binary("hyprpicker");
link_sub_binary("xdg-desktop-portal-wlr");
link_script("playerctl-toggle.pl");
link_script("status.pl");

@ -0,0 +1 @@
Subproject commit 8a7799ae20f3e2e2e716271c21fc9213319ca2a4

View File

@ -15,7 +15,7 @@ srcs = [
]
executable(
'shortcuts',
'net.iotib.Shortcuts',
sources: srcs,
dependencies: deps,
install: true,

View File

@ -4,7 +4,7 @@
* notice and this notice are preserved. This program is offered as-is,
* without any warranty. */
const string license = """ Charadon <dev@iotib.net> (c) 2024
const string LICENSE = """ Charadon <dev@iotib.net> (c) 2024
Copying and distribution of this program, with or without modification,
are permitted in any medium without royalty provided the copyright

View File

@ -5,8 +5,11 @@
* without any warranty. */
using Gtk;
ShortcutsApp app;
public class ShortcutsApp: Gtk.Application {
private Gtk.Stack stack;
private Gtk.ApplicationWindow window;
private class Shortcut: Gtk.Box {
private Gtk.ShortcutLabel shortcut;
@ -83,7 +86,7 @@ public class ShortcutsApp: Gtk.Application {
foreach(Shortcut i in shortcuts) {
box.add(i);
}
stack.add_titled(box, "normal_mode", "Normal Mode");a
stack.add_titled(box, "normal_mode", "Normal Mode");
return;
}
@ -104,9 +107,13 @@ public class ShortcutsApp: Gtk.Application {
/* Application Launcher */
Shortcut shortcuts[] = {
new Shortcut("Super_L&a", "Enters Shortcut Mode."),
new Shortcut("f", "Spawns Firefox."),
new Shortcut("Escape", "Leaves Mode."),
new Shortcut("w", "Spawns Web browser."),
new Shortcut("t", "Spawns Terminal."),
new Shortcut("g", "Toggles Guake.")
new Shortcut("g", "Toggles Guake."),
new Shortcut("f", "Spawns File Manager."),
new Shortcut("c", "Spawns Calculator."),
new Shortcut("s", "Open System Monitor/Task Manager."),
};
foreach(Shortcut i in shortcuts) {
box.add(i);
@ -115,11 +122,63 @@ public class ShortcutsApp: Gtk.Application {
return;
}
private void show_about_dialog() {
var aboutDialog = new Gtk.AboutDialog();
aboutDialog.default_width = 320;
aboutDialog.default_height = 240;
aboutDialog.authors = {"Charadon"};
aboutDialog.license = LICENSE;
aboutDialog.copyright = "Charadon (c) 2024";
aboutDialog.logo_icon_name = "input-keyboard-symbolic";
aboutDialog.program_name = "Shortcuts";
aboutDialog.version = "v1.0.0";
aboutDialog.wrap_license = true;
aboutDialog.modal = true;
aboutDialog.set_transient_for(window);
aboutDialog.website = "https://git.iotib.net/Charadon/dwl";
window.set_sensitive(false);
aboutDialog.response.connect((response_id)=>{
if(response_id == Gtk.ResponseType.DELETE_EVENT) {
aboutDialog.destroy();
aboutDialog = null;
window.set_sensitive(true);
};
});
aboutDialog.show();
return;
}
private void populate_menu_bar() {
var menubar = new GLib.Menu();
/* File Menu */
var fileMenu = new GLib.Menu();
var closeApp = new GLib.SimpleAction("close-app", null);
closeApp.activate.connect(this.quit);
this.add_action(closeApp);
var closeAppMenuItem = new GLib.MenuItem("_Close", "app.close-app");
fileMenu.append_item(closeAppMenuItem);
/* Help Menu */
var helpMenu = new GLib.Menu();
/* About */
var showAboutDialog = new GLib.SimpleAction("show_about", null);
showAboutDialog.activate.connect(show_about_dialog);
this.add_action(showAboutDialog);
var showAbout = new GLib.MenuItem("_About", @"app.show_about");
helpMenu.append_item(showAbout);
/* Create Menubar */
menubar.append_submenu("_File", fileMenu);
menubar.append_submenu("_Help", helpMenu);
this.set_menubar(menubar);
}
private void populate_power_mode() {
var box = new Gtk.Box(Gtk.Orientation.VERTICAL, 5) {
vexpand = true,
margin_bottom = 5,
};
populate_menu_bar();
/* Title */
var title = new Gtk.Label("<b>Power Mode Keyboard Shortcuts</b>") {
halign = Gtk.Align.START,
@ -133,6 +192,7 @@ public class ShortcutsApp: Gtk.Application {
/* Application Launcher */
Shortcut shortcuts[] = {
new Shortcut("Super_L&p", "Enter Power Mode."),
new Shortcut("Escape", "Leaves Mode."),
new Shortcut("Delete", "Shutsdown Computer."),
new Shortcut("Page_Down", "Reboots Computer."),
new Shortcut("Pause", "Suspends Computer."),
@ -144,26 +204,6 @@ public class ShortcutsApp: Gtk.Application {
return;
}
private void populate_licenses() {
var box = new Gtk.Box(Gtk.Orientation.VERTICAL, 5);
var textView = new Gtk.TextView() {
editable = false,
vexpand = true,
};
var textBuffer = new Gtk.TextBuffer(null);
textView.set_buffer(textBuffer);
textBuffer.text = license; /* See: src/license.vala */
box.add(textView);
stack.add_titled(box, "licenses", "Licenses");
return;
}
private void populate_about() {
var box = new Gtk.Box(Gtk.Orientation.VERTICAL, 5);
stack.add_titled(box, "about", "About");
return;
}
public ShortcutsApp() {
this.application_id = "net.iotib.DWLHelp";
this.flags = GLib.ApplicationFlags.FLAGS_NONE;
@ -171,12 +211,10 @@ public class ShortcutsApp: Gtk.Application {
}
protected override void activate() {
var window = new Gtk.ApplicationWindow(this) {
window = new Gtk.ApplicationWindow(this) {
title = "DWL Help",
width_request = 1024,
height_request = 480,
};
window.name = "net.iotib.DWLHelp";
window.set_size_request(1024, 480);
window.set_default_size(1024, 480);
var mainBox = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0) {
@ -203,8 +241,6 @@ public class ShortcutsApp: Gtk.Application {
populate_normal_mode();
populate_shortcut_mode();
populate_power_mode();
populate_licenses();
populate_about();
/* Render */
window.show_all();
@ -214,6 +250,7 @@ public class ShortcutsApp: Gtk.Application {
int main(string[] Args) {
var app = new ShortcutsApp();
GLib.Environment.set_variable("GDK_BACKEND", "wayland", false);
app = new ShortcutsApp();
return(app.run());
}