commit 7c014daab02cb2012dbc7b6b1ddb2f570be410e2
parent 5a14313d48ac80fb92b59bb0fbbc8b56cd674711
Author: MTRNord <mtrnord1@gmail.com>
Date: Mon, 21 Dec 2020 20:35:15 +0100
feat: Add Spotify and Mumble handling
Took 27 minutes
Diffstat:
5 files changed, 101 insertions(+), 13 deletions(-)
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
@@ -6,17 +6,11 @@
</component>
<component name="ChangeListManager">
<list default="true" id="cfc5721f-cc06-4df2-8555-3745919e4c56" name="Default Changelist" comment="">
- <change afterPath="$PROJECT_DIR$/lsc_matrix_presets/src/config.rs" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" 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$/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$/lsc_example_plugin/Cargo.toml" beforeDir="false" afterPath="$PROJECT_DIR$/lsc_example_plugin/Cargo.toml" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/lsc_example_plugin/src/main.rs" beforeDir="false" afterPath="$PROJECT_DIR$/lsc_example_plugin/src/main.rs" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/lsc_matrix_presets/Cargo.toml" beforeDir="false" afterPath="$PROJECT_DIR$/lsc_matrix_presets/Cargo.toml" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/lsc_matrix_presets/src/main.rs" beforeDir="false" afterPath="$PROJECT_DIR$/lsc_matrix_presets/src/main.rs" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -24,7 +18,7 @@
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="DarkyenusTimeTracker">
- <option name="totalTimeSeconds" value="21452" />
+ <option name="totalTimeSeconds" value="23079" />
<option name="idleThresholdMs" value="60000" />
<option name="autoCountIdleSeconds" value="0" />
<option name="stopWhenIdleRatherThanPausing" value="true" />
@@ -137,7 +131,10 @@
<workItem from="1607716945713" duration="4563000" />
<workItem from="1607936162789" duration="15000" />
<workItem from="1608061205255" duration="763000" />
- <workItem from="1608229569199" duration="21320000" />
+ <workItem from="1608229569199" duration="23592000" />
+ <workItem from="1608549168444" duration="10000" />
+ <workItem from="1608556330627" duration="91000" />
+ <workItem from="1608573275369" duration="1142000" />
</task>
<task id="LOCAL-00001" summary="refactor: Use Workspace setup">
<created>1607182699156</created>
@@ -188,7 +185,14 @@
<option name="project" value="LOCAL" />
<updated>1608250883243</updated>
</task>
- <option name="localTasksCounter" value="8" />
+ <task id="LOCAL-00008" summary="feat: Add alphaish matrix integration">
+ <created>1608308389146</created>
+ <option name="number" value="00008" />
+ <option name="presentableId" value="LOCAL-00008" />
+ <option name="project" value="LOCAL" />
+ <updated>1608308389146</updated>
+ </task>
+ <option name="localTasksCounter" value="9" />
<servers />
</component>
<component name="VcsManagerConfiguration">
@@ -200,7 +204,8 @@
<MESSAGE value="feat: Prepare Matrix and Layers" />
<MESSAGE value="refactor: Move layer action keys out of layer" />
<MESSAGE value="feat: Implement layers fully" />
- <option name="LAST_COMMIT_MESSAGE" value="feat: Implement layers fully" />
+ <MESSAGE value="feat: Add alphaish matrix integration" />
+ <option name="LAST_COMMIT_MESSAGE" value="feat: Add alphaish matrix integration" />
</component>
<component name="XSLT-Support.FileAssociations.UIState">
<expand />
diff --git a/Cargo.lock b/Cargo.lock
@@ -644,6 +644,16 @@ dependencies = [
]
[[package]]
+name = "dbus"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "22c08adfeb70c940c14d8af988fa854dcb5529e6141f2397e4e0fa4c9375d094"
+dependencies = [
+ "libc",
+ "libdbus-sys",
+]
+
+[[package]]
name = "digest"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1198,6 +1208,7 @@ version = "0.1.0"
dependencies = [
"alsa",
"color-eyre",
+ "dbus 0.9.0",
"futures-util",
"midir",
"notify-rust",
@@ -1666,7 +1677,7 @@ version = "4.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "144acee6a0543dc74893e4b8a33936b5b0a94cc2d4ab024afd0c6daff7afc3c0"
dependencies = [
- "dbus",
+ "dbus 0.8.4",
"mac-notification-sys",
"winrt-notification",
]
diff --git a/launchpad_sway_controler/Cargo.toml b/launchpad_sway_controler/Cargo.toml
@@ -18,4 +18,5 @@ tracing-subscriber = "0.2"
thirtyfour = "0.21"
once_cell = "1.4.1"
notify-rust = "4"
-users = "0.11.0"
-\ No newline at end of file
+users = "0.11.0"
+dbus = "0.9.0"
+\ No newline at end of file
diff --git a/launchpad_sway_controler/src/mappings/mod.rs b/launchpad_sway_controler/src/mappings/mod.rs
@@ -11,6 +11,11 @@ pub static LAYERS: [&'static [(i64, PluginActions)]; 10] = [
(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),
],
&[(0, PluginActions::ExamplePlugin)],
&[
diff --git a/launchpad_sway_controler/src/plugin_actions/mod.rs b/launchpad_sway_controler/src/plugin_actions/mod.rs
@@ -2,12 +2,15 @@ use crate::reset_colors;
use crate::utils::globals::{LAYER_NUMBER, PRESELECTED_LAYER_NUMBER, SHOWING_NUMBER};
use crate::utils::show_number;
use color_eyre::Result;
+use dbus::blocking::Connection as DBUSConnection;
use midir::MidiOutput;
use notify_rust::{Notification, Timeout};
use std::sync::atomic::Ordering;
+use std::time::Duration;
use swayipc_async::Connection;
use tokio::io::AsyncWriteExt;
use tokio::net::UnixStream;
+use tracing::*;
use users::get_current_uid;
pub enum PluginActions<'a> {
@@ -18,6 +21,11 @@ pub enum PluginActions<'a> {
RunMatrixPreset(&'a str),
ShowNumber(usize),
SelectLayer,
+ MumbleToggleMute,
+ MumbleToggleDeaf,
+ SpotifyNextTrack,
+ SpotifyPrevTrack,
+ SpotifyPause,
}
impl PluginActions<'_> {
@@ -87,6 +95,64 @@ impl PluginActions<'_> {
SHOWING_NUMBER.store(false, Ordering::SeqCst);
reset_colors(&mut conn_out);
}
+ PluginActions::MumbleToggleMute => {
+ let conn = DBUSConnection::new_session()?;
+ let proxy = conn.with_proxy(
+ "net.sourceforge.mumble.mumble",
+ "/",
+ Duration::from_millis(5000),
+ );
+ let (muted,): (bool,) =
+ proxy.method_call("net.sourceforge.mumble.Mumble", "isSelfMuted", ())?;
+ notification(format!("Changed muted to: {}", !muted).as_str());
+ let (): () = proxy.method_call(
+ "net.sourceforge.mumble.Mumble",
+ "setSelfMuted",
+ (!muted,),
+ )?;
+ }
+ PluginActions::MumbleToggleDeaf => {
+ let conn = DBUSConnection::new_session()?;
+ let proxy = conn.with_proxy(
+ "net.sourceforge.mumble.mumble",
+ "/",
+ Duration::from_millis(5000),
+ );
+ let (deaf,): (bool,) =
+ proxy.method_call("net.sourceforge.mumble.Mumble", "isSelfDeaf", ())?;
+ notification(format!("Changed Deaf to: {}", !deaf).as_str());
+ let (): () =
+ proxy.method_call("net.sourceforge.mumble.Mumble", "setSelfDeaf", (!deaf,))?;
+ }
+ PluginActions::SpotifyNextTrack => {
+ let conn = DBUSConnection::new_session()?;
+ let proxy = conn.with_proxy(
+ "org.mpris.MediaPlayer2.spotify",
+ "/org/mpris/MediaPlayer2",
+ Duration::from_millis(5000),
+ );
+ let (): () = proxy.method_call("org.mpris.MediaPlayer2.Player", "Next", ())?;
+ }
+ PluginActions::SpotifyPrevTrack => {
+ let conn = DBUSConnection::new_session()?;
+ let proxy = conn.with_proxy(
+ "org.mpris.MediaPlayer2.spotify",
+ "/org/mpris/MediaPlayer2",
+ Duration::from_millis(5000),
+ );
+ // We send it twice as it first just goes back to the track start
+ let (): () = proxy.method_call("org.mpris.MediaPlayer2.Player", "Previous", ())?;
+ let (): () = proxy.method_call("org.mpris.MediaPlayer2.Player", "Previous", ())?;
+ }
+ PluginActions::SpotifyPause => {
+ let conn = DBUSConnection::new_session()?;
+ let proxy = conn.with_proxy(
+ "org.mpris.MediaPlayer2.spotify",
+ "/org/mpris/MediaPlayer2",
+ Duration::from_millis(5000),
+ );
+ let (): () = proxy.method_call("org.mpris.MediaPlayer2.Player", "PlayPause", ())?;
+ }
}
Ok(())
}