sway-launchpad

A small rust script to switch sway workspaces using a Launchpad S
git clone git://archive.git.mtrnord.blog/MTRNord/sway-launchpad.git
Log | Files | Refs | LICENSE

commit 6723646c23faf26cadcd78179ba562b802d8649e
parent 7c014daab02cb2012dbc7b6b1ddb2f570be410e2
Author: MTRNord <mtrnord1@gmail.com>
Date:   Tue, 22 Dec 2020 10:39:10 +0100

feat: Add Colors to mappings

Took 24 minutes

Diffstat:
M.idea/LaunchpadSwayControler.iml | 1+
M.idea/workspace.xml | 29+++++++++++++++++++++--------
MCargo.lock | 10++++++++++
MCargo.toml | 3++-
Mlaunchpad_sway_controler/src/main.rs | 20++++++++++++--------
Mlaunchpad_sway_controler/src/mappings/mod.rs | 46+++++++++++++++++++++++++++++-----------------
Mlaunchpad_sway_controler/src/utils/mod.rs | 8++++----
Alaunchpad_sway_controler_macros/Cargo.toml | 17+++++++++++++++++
Alaunchpad_sway_controler_macros/src/lib.rs | 6++++++
9 files changed, 102 insertions(+), 38 deletions(-)

diff --git a/.idea/LaunchpadSwayControler.iml b/.idea/LaunchpadSwayControler.iml @@ -6,6 +6,7 @@ <sourceFolder url="file://$MODULE_DIR$/launchpad_sway_controler/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/lsc_example_plugin/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/lsc_matrix_presets/src" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/launchpad_sway_controler_macros/src" isTestSource="false" /> <excludeFolder url="file://$MODULE_DIR$/target" /> </content> <orderEntry type="inheritedJdk" /> diff --git a/.idea/workspace.xml b/.idea/workspace.xml @@ -6,11 +6,15 @@ </component> <component name="ChangeListManager"> <list default="true" id="cfc5721f-cc06-4df2-8555-3745919e4c56" name="Default Changelist" comment=""> + <change afterPath="$PROJECT_DIR$/launchpad_sway_controler_macros/Cargo.toml" afterDir="false" /> + <change afterPath="$PROJECT_DIR$/launchpad_sway_controler_macros/src/lib.rs" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/.idea/LaunchpadSwayControler.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/LaunchpadSwayControler.iml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/Cargo.lock" beforeDir="false" afterPath="$PROJECT_DIR$/Cargo.lock" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/launchpad_sway_controler/Cargo.toml" beforeDir="false" afterPath="$PROJECT_DIR$/launchpad_sway_controler/Cargo.toml" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/Cargo.toml" beforeDir="false" afterPath="$PROJECT_DIR$/Cargo.toml" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/launchpad_sway_controler/src/main.rs" beforeDir="false" afterPath="$PROJECT_DIR$/launchpad_sway_controler/src/main.rs" afterDir="false" /> <change beforePath="$PROJECT_DIR$/launchpad_sway_controler/src/mappings/mod.rs" beforeDir="false" afterPath="$PROJECT_DIR$/launchpad_sway_controler/src/mappings/mod.rs" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/launchpad_sway_controler/src/plugin_actions/mod.rs" beforeDir="false" afterPath="$PROJECT_DIR$/launchpad_sway_controler/src/plugin_actions/mod.rs" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/launchpad_sway_controler/src/utils/mod.rs" beforeDir="false" afterPath="$PROJECT_DIR$/launchpad_sway_controler/src/utils/mod.rs" afterDir="false" /> </list> <option name="SHOW_DIALOG" value="false" /> <option name="HIGHLIGHT_CONFLICTS" value="true" /> @@ -18,7 +22,7 @@ <option name="LAST_RESOLUTION" value="IGNORE" /> </component> <component name="DarkyenusTimeTracker"> - <option name="totalTimeSeconds" value="23079" /> + <option name="totalTimeSeconds" value="24522" /> <option name="idleThresholdMs" value="60000" /> <option name="autoCountIdleSeconds" value="0" /> <option name="stopWhenIdleRatherThanPausing" value="true" /> @@ -48,15 +52,16 @@ <property name="RunOnceActivity.OpenProjectViewOnStart" value="true" /> <property name="RunOnceActivity.ShowReadmeOnStart" value="true" /> <property name="WebServerToolWindowFactoryState" value="false" /> - <property name="last_opened_file_path" value="$PROJECT_DIR$/lsc_example_plugin/src" /> + <property name="last_opened_file_path" value="$PROJECT_DIR$/launchpad_sway_controler/src" /> <property name="org.rust.cargo.project.model.PROJECT_DISCOVERY" value="true" /> - <property name="project.structure.last.edited" value="Project" /> + <property name="project.structure.last.edited" value="Modules" /> <property name="project.structure.proportion" value="0.0" /> <property name="project.structure.side.proportion" value="0.2" /> <property name="settings.editor.selected.configurable" value="language.rust.rustfmt" /> </component> <component name="RecentsManager"> <key name="CopyFile.RECENT_KEYS"> + <recent name="$PROJECT_DIR$/launchpad_sway_controler/src" /> <recent name="$PROJECT_DIR$/lsc_example_plugin/src" /> <recent name="$PROJECT_DIR$" /> </key> @@ -134,7 +139,7 @@ <workItem from="1608229569199" duration="23592000" /> <workItem from="1608549168444" duration="10000" /> <workItem from="1608556330627" duration="91000" /> - <workItem from="1608573275369" duration="1142000" /> + <workItem from="1608573275369" duration="4354000" /> </task> <task id="LOCAL-00001" summary="refactor: Use Workspace setup"> <created>1607182699156</created> @@ -192,7 +197,14 @@ <option name="project" value="LOCAL" /> <updated>1608308389146</updated> </task> - <option name="localTasksCounter" value="9" /> + <task id="LOCAL-00009" summary="feat: Add Spotify and Mumble handling"> + <created>1608579315670</created> + <option name="number" value="00009" /> + <option name="presentableId" value="LOCAL-00009" /> + <option name="project" value="LOCAL" /> + <updated>1608579315670</updated> + </task> + <option name="localTasksCounter" value="10" /> <servers /> </component> <component name="VcsManagerConfiguration"> @@ -205,7 +217,8 @@ <MESSAGE value="refactor: Move layer action keys out of layer" /> <MESSAGE value="feat: Implement layers fully" /> <MESSAGE value="feat: Add alphaish matrix integration" /> - <option name="LAST_COMMIT_MESSAGE" value="feat: Add alphaish matrix integration" /> + <MESSAGE value="feat: Add Spotify and Mumble handling" /> + <option name="LAST_COMMIT_MESSAGE" value="feat: Add Spotify and Mumble handling" /> </component> <component name="XSLT-Support.FileAssociations.UIState"> <expand /> diff --git a/Cargo.lock b/Cargo.lock @@ -1222,6 +1222,16 @@ dependencies = [ ] [[package]] +name = "launchpad_sway_controler_macros" +version = "0.1.0" +dependencies = [ + "nom", + "proc-macro2", + "quote 1.0.7", + "syn 1.0.53", +] + +[[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/Cargo.toml b/Cargo.toml @@ -2,7 +2,8 @@ members = [ "launchpad_sway_controler", "lsc_example_plugin", - "lsc_matrix_presets" + "lsc_matrix_presets", + "launchpad_sway_controler_macros" ] [profile.dev.package.backtrace] diff --git a/launchpad_sway_controler/src/main.rs b/launchpad_sway_controler/src/main.rs @@ -20,20 +20,24 @@ mod utils; fn reset_colors(conn_out: &mut MidiOutputConnection) { conn_out.send(&[176, 0, 0]).unwrap(); - for (value, _) in LAYERS[LAYER_NUMBER.load(Ordering::SeqCst) as usize].iter() { + for (value, color, _) in LAYERS[LAYER_NUMBER.load(Ordering::SeqCst) as usize].iter() { conn_out - .send(&[144, (*value as i32).try_into().unwrap(), 15]) + .send(&[ + 144, + (*value as i32).try_into().unwrap(), + (*color as i32).try_into().unwrap(), + ]) .unwrap(); } - conn_out.send(&[144, 24, 15]).unwrap(); - conn_out.send(&[144, 8, 15]).unwrap(); - conn_out.send(&[144, 40, 15]).unwrap(); + conn_out.send(&[144, 24, 63]).unwrap(); + conn_out.send(&[144, 8, 63]).unwrap(); + conn_out.send(&[144, 40, 63]).unwrap(); if let Ok(workspace) = sway::WorkspaceLaunchpadMapping::try_from(CURRENT_WORKSPACE.load(Ordering::SeqCst) as i32) { if LAYER_NUMBER.load(Ordering::SeqCst) == workspace.get_layer() { conn_out - .send(&[144, (workspace as i32).try_into().unwrap(), 28]) + .send(&[144, (workspace as i32).try_into().unwrap(), 60]) .unwrap(); } } @@ -103,8 +107,8 @@ async fn main() -> Result<()> { if let Some(action) = LAYERS[LAYER_NUMBER.load(Ordering::SeqCst) as usize] .iter() - .find(|(x, _)| *x == message[1] as i64) - .map(|(_, y)| y) + .find(|(x, _, _)| *x == message[1] as i64) + .map(|(_, _, y)| y) { run_action(Runtime::new().unwrap(), action); } diff --git a/launchpad_sway_controler/src/mappings/mod.rs b/launchpad_sway_controler/src/mappings/mod.rs @@ -1,33 +1,45 @@ use crate::plugin_actions::PluginActions; -pub static LAYERS: [&'static [(i64, PluginActions)]; 10] = [ +#[allow(dead_code)] +#[derive(Copy, Clone, Debug)] +pub enum Color { + Red = 15, + Green = 60, + Orange = 47, + Yellow = 62, + Amber = 63, +} + +pub static LAYERS: [&'static [(i64, Color, PluginActions)]; 10] = [ &[ - (120, PluginActions::SwayBack), - (119, PluginActions::SwayWorkspace("1:\u{e007}")), - (118, PluginActions::SwayWorkspace("2:\u{f086}")), - (117, PluginActions::SwayWorkspace("3:\u{f0e0}")), - (116, PluginActions::SwayWorkspace("5:\u{f1c9}")), - (115, PluginActions::SwayWorkspace("11:\u{f1b6}")), - (114, PluginActions::SwayWorkspace("12:\u{f11b}")), - (113, PluginActions::SwayWorkspace("13:\u{f167}")), - (112, PluginActions::SwayWorkspace("42:\u{f001}")), - (102, PluginActions::MumbleToggleMute), - (103, PluginActions::MumbleToggleDeaf), - (109, PluginActions::SpotifyPrevTrack), //TODO investigate why 109-111 do not light up (They are undocumented) - (110, PluginActions::SpotifyPause), - (111, PluginActions::SpotifyNextTrack), + (120, Color::Orange, PluginActions::SwayBack), + (119, Color::Red, PluginActions::SwayWorkspace("1:\u{e007}")), + (118, Color::Red, PluginActions::SwayWorkspace("2:\u{f086}")), + (117, Color::Red, PluginActions::SwayWorkspace("3:\u{f0e0}")), + (116, Color::Red, PluginActions::SwayWorkspace("5:\u{f1c9}")), + (115, Color::Red, PluginActions::SwayWorkspace("11:\u{f1b6}")), + (114, Color::Red, PluginActions::SwayWorkspace("12:\u{f11b}")), + (113, Color::Red, PluginActions::SwayWorkspace("13:\u{f167}")), + (112, Color::Red, PluginActions::SwayWorkspace("42:\u{f001}")), + (102, Color::Orange, PluginActions::MumbleToggleMute), + (103, Color::Orange, PluginActions::MumbleToggleDeaf), + (109, Color::Amber, PluginActions::SpotifyPrevTrack), //TODO investigate why 109-111 do not light up (They are undocumented) + (110, Color::Amber, PluginActions::SpotifyPause), + (111, Color::Amber, PluginActions::SpotifyNextTrack), ], - &[(0, PluginActions::ExamplePlugin)], + &[(0, Color::Red, PluginActions::ExamplePlugin)], &[ ( 0, + Color::Amber, PluginActions::SelectMatrixRoomByID("!IFqsVhqzXtALgXIFig:bpulse.org"), ), ( 1, + Color::Amber, PluginActions::SelectMatrixRoomByID("!FJymnHKxIlQeNDkaZW:ubports.chat"), ), - (17, PluginActions::RunMatrixPreset("0")), + (17, Color::Yellow, PluginActions::RunMatrixPreset("0")), ], &[], &[], diff --git a/launchpad_sway_controler/src/utils/mod.rs b/launchpad_sway_controler/src/utils/mod.rs @@ -11,9 +11,9 @@ pub fn show_number(conn_out: &mut MidiOutputConnection, number: usize) { SHOWING_NUMBER.store(true, Ordering::SeqCst); conn_out.send(&[176, 0, 0]).unwrap(); show_array(conn_out, NUMBERS[number]); - conn_out.send(&[144, 24, 47]).unwrap(); - conn_out.send(&[144, 8, 47]).unwrap(); - conn_out.send(&[144, 40, 47]).unwrap(); + conn_out.send(&[144, 24, 63]).unwrap(); + conn_out.send(&[144, 8, 63]).unwrap(); + conn_out.send(&[144, 40, 63]).unwrap(); } pub fn show_array(conn_out: &mut MidiOutputConnection, array: [[bool; 8]; 8]) { @@ -22,7 +22,7 @@ pub fn show_array(conn_out: &mut MidiOutputConnection, array: [[bool; 8]; 8]) { if *column { let key = INNER_KEYS[row_n][column_n]; conn_out - .send(&[144, (key as i32).try_into().unwrap(), 15]) + .send(&[144, (key as i32).try_into().unwrap(), 60]) .unwrap(); } } diff --git a/launchpad_sway_controler_macros/Cargo.toml b/launchpad_sway_controler_macros/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "launchpad_sway_controler_macros" +version = "0.1.0" +authors = ["MTRNord <mtrnord1@gmail.com>"] +edition = "2018" + +[lib] +proc-macro = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +syn = {version = "1.0", features = ["full"]} +quote = "1.0" +proc-macro2 = "1.0" +nom = "6.0.1" +\ No newline at end of file diff --git a/launchpad_sway_controler_macros/src/lib.rs b/launchpad_sway_controler_macros/src/lib.rs @@ -0,0 +1,6 @@ +#![feature(proc_macro_diagnostic)] + +use proc_macro2::TokenStream; + +#[proc_macro] +pub fn compile_mappings(input: TokenStream) -> TokenStream {}