Skip to content

Commit

Permalink
Added command to raise the player(s) window if hidden or minimized
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusor committed Aug 21, 2024
1 parent f3ad167 commit 3665b11
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
21 changes: 17 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define CMD_NEXT "next"
#define CMD_PREVIOUS "prev"
#define CMD_PLAY_PAUSE "pp"
#define CMD_RAISE "raise"
#define CMD_STATUS "status"
#define CMD_SEEK "seek"
#define CMD_SHUFFLE "shuffle"
Expand Down Expand Up @@ -113,6 +114,8 @@ ARG_PLAYER" "PLAYER_ACTIVE"\t\tExecute command only for the active player(s) (de
"\t\t\tThe percentage can be prefixed by a \"+\", or a \"-\", to increase, or decrease the volume by the respective value.\n" \
"\t\t\tIf the percentage argument is not present, the current volume will be output (equivalent to '" CMD_INFO " %" INFO_VOLUME "').\n" \
"\n" \
"\t" CMD_RAISE "\t\tRaise the window of the player if hidden.\n" \
"\n" \
"\t" CMD_STATUS "\t\tGet the playback status (equivalent to '" CMD_INFO " %" INFO_PLAYBACK_STATUS "')\n" \
"\t" CMD_LIST "\t\tGet the name of the running player(s) (equivalent to '" CMD_INFO " %" INFO_PLAYER_NAME "')\n" \
"\t" CMD_INFO "\t\t<format> Display information about the current track.\n" \
Expand Down Expand Up @@ -145,8 +148,8 @@ const char* get_version(void)
return VERSION_HASH;
}

const char commands[14][9] = {CMD_HELP, CMD_PLAY, CMD_PAUSE, CMD_STOP, CMD_NEXT, CMD_PREVIOUS,
CMD_PLAY_PAUSE, CMD_STATUS, CMD_SEEK, CMD_LIST, CMD_INFO, CMD_SHUFFLE, CMD_REPEAT, CMD_VOLUME, };
const char commands[15][9] = {CMD_HELP, CMD_PLAY, CMD_PAUSE, CMD_STOP, CMD_NEXT, CMD_PREVIOUS,
CMD_PLAY_PAUSE, CMD_RAISE, CMD_STATUS, CMD_SEEK, CMD_LIST, CMD_INFO, CMD_SHUFFLE, CMD_REPEAT, CMD_VOLUME, };

enum cmd {
c_help,
Expand All @@ -163,6 +166,7 @@ enum cmd {
c_shuffle,
c_repeat,
c_volume,
c_raise,

c_count
};
Expand Down Expand Up @@ -215,6 +219,9 @@ const char *get_dbus_method (enum cmd command)
if (command == c_status || command == c_info || command == c_list) {
return DBUS_INTERFACE_PROPERTIES;
}
if (command == c_raise) {
return MPRIS_METHOD_RAISE;
}

return NULL;
}
Expand Down Expand Up @@ -541,6 +548,8 @@ int main(int argc, char** argv)
cmd.command = c_pause;
} else if (strncmp(command, CMD_PREVIOUS, strlen(CMD_PREVIOUS)) == 0) {
cmd.command = c_previous;
} else if (strncmp(command, CMD_RAISE, strlen(CMD_RAISE)) == 0) {
cmd.command = c_raise;
} else if (strncmp(command, CMD_NEXT, strlen(CMD_NEXT)) == 0) {
cmd.command = c_next;
} else if (strncmp(command, CMD_STOP, strlen(CMD_STOP)) == 0) {
Expand Down Expand Up @@ -626,7 +635,7 @@ int main(int argc, char** argv)
mpris_player player = cmd.players[i];
if (player.skip) {
if (cmd.player_names[0][0] != 0) continue;
if (cmd.command != c_play) continue;
if (cmd.command != c_play && cmd.command != c_raise) continue;
}

if (cmd.command == c_info || cmd.command == c_status || cmd.command == c_list) {
Expand Down Expand Up @@ -680,7 +689,11 @@ int main(int argc, char** argv)
cmd.status = EXIT_SUCCESS;
}
} else {
DBusMessage *msg = call_dbus_method(conn, player.namespace, MPRIS_PLAYER_PATH, MPRIS_PLAYER_INTERFACE, dbus_method);
const char* interface = MPRIS_MEDIA_PLAYER_PLAYER_INTERFACE;
if (cmd.command == c_raise) {
interface = MPRIS_MEDIA_PLAYER_INTERFACE;
}
DBusMessage *msg = call_dbus_method(conn, player.namespace, MPRIS_PLAYER_PATH, interface, dbus_method);
if (NULL != msg) {
cmd.status = EXIT_SUCCESS;
}
Expand Down
15 changes: 9 additions & 6 deletions src/sdbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
#include <stdio.h>
#include <dbus/dbus.h>

#define MPRIS_MEDIA_PLAYER_PLAYER_INTERFACE "org.mpris.MediaPlayer2.Player"
#define MPRIS_MEDIA_PLAYER_INTERFACE "org.mpris.MediaPlayer2"

#define LOCAL_NAME "org.mpris.mprisctl"
#define MPRIS_PLAYER_NAMESPACE "org.mpris.MediaPlayer2"
#define MPRIS_PLAYER_PATH "/org/mpris/MediaPlayer2"
#define MPRIS_PLAYER_INTERFACE "org.mpris.MediaPlayer2.Player"
#define MPRIS_METHOD_NEXT "Next"
#define MPRIS_METHOD_PREVIOUS "Previous"
#define MPRIS_METHOD_PLAY "Play"
#define MPRIS_METHOD_PAUSE "Pause"
#define MPRIS_METHOD_STOP "Stop"
#define MPRIS_METHOD_PLAY_PAUSE "PlayPause"
#define MPRIS_METHOD_SEEK "Seek"
#define MPRIS_METHOD_RAISE "Raise"

#define MPRIS_PNAME_PLAYBACKSTATUS "PlaybackStatus"
#define MPRIS_PNAME_CANCONTROL "CanControl"
Expand Down Expand Up @@ -457,7 +460,7 @@ void load_mpris_properties(DBusConnection* conn, const char* destination, mpris_
const char* interface = DBUS_INTERFACE_PROPERTIES;
const char* method = DBUS_METHOD_GET_ALL;
const char* path = MPRIS_PLAYER_PATH;
const char* arg_interface = MPRIS_PLAYER_INTERFACE;
const char* arg_interface = MPRIS_MEDIA_PLAYER_PLAYER_INTERFACE;

// create a new method call and check for errors
DBusMessage* msg = dbus_message_new_method_call(destination, path, interface, method);
Expand Down Expand Up @@ -587,7 +590,7 @@ int seek(DBusConnection* conn, const mpris_player player, const int ms)
dbus_error_init(&err);

// create a new method call and check for errors
DBusMessage* msg = dbus_message_new_method_call(player.namespace, MPRIS_PLAYER_PATH, MPRIS_PLAYER_INTERFACE, MPRIS_METHOD_SEEK);
DBusMessage* msg = dbus_message_new_method_call(player.namespace, MPRIS_PLAYER_PATH, MPRIS_MEDIA_PLAYER_PLAYER_INTERFACE, MPRIS_METHOD_SEEK);
if (NULL == msg) { return status; }

const int64_t usec = ms * 1000;
Expand Down Expand Up @@ -643,7 +646,7 @@ int shuffle(DBusConnection* conn, const mpris_player player, const bool *state)
DBusPendingCall* pending;
DBusMessageIter args;

char* arg_interface = MPRIS_PLAYER_INTERFACE;
char* arg_interface = MPRIS_MEDIA_PLAYER_PLAYER_INTERFACE;
char* arg_shuffle = MPRIS_PNAME_SHUFFLE;

// create a new method call and check for errors
Expand Down Expand Up @@ -716,7 +719,7 @@ int set_loopstatus(DBusConnection* conn, const mpris_player player, const char*
DBusPendingCall* pending;
DBusMessageIter args;

char* arg_interface = MPRIS_PLAYER_INTERFACE;
char* arg_interface = MPRIS_MEDIA_PLAYER_PLAYER_INTERFACE;
char* arg_loopstatus = MPRIS_PNAME_LOOPSTATUS;

// create a new method call and check for errors
Expand Down Expand Up @@ -789,7 +792,7 @@ int set_volume(DBusConnection* conn, const mpris_player player, const double vol
DBusPendingCall* pending;
DBusMessageIter args;

const char* arg_interface = MPRIS_PLAYER_INTERFACE;
const char* arg_interface = MPRIS_MEDIA_PLAYER_PLAYER_INTERFACE;
const char* arg_volume = MPRIS_PNAME_VOLUME;

// create a new method call and check for errors
Expand Down

0 comments on commit 3665b11

Please sign in to comment.