From df030f4a68322cfdc1487bf0b77c43c6ff339be1 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Wed, 13 Sep 2017 16:25:10 +0200 Subject: [PATCH 1/4] Init Nix derivation for simple development --- shell.nix | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 shell.nix diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..d3deab9 --- /dev/null +++ b/shell.nix @@ -0,0 +1,9 @@ +with import {}; stdenv.mkDerivation { + name = "yabar-dev"; + src = ./.; + + buildInputs = [ + cairo gdk_pixbuf libconfig pango pkgconfig xorg.xcbutilwm docbook_xsl + alsaLib wirelesstools asciidoc libxslt makeWrapper libxml2 + ]; +} From 027fd7df3dab223ea63b6022f8c491b0322d4120 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Fri, 15 Sep 2017 18:02:15 +0200 Subject: [PATCH 2/4] Add simple block for `playerctl` --- Makefile | 2 +- doc/yabar.1.asciidoc | 6 ++++ examples/example.config | 6 ++++ shell.nix | 2 +- src/intern_blks/ya_intern.c | 62 +++++++++++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 38a77ed..9a78be4 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ CPPFLAGS += -DVERSION=\"$(VERSION)\" -D_POSIX_C_SOURCE=199309L -DYA_INTERNAL -DY -DYA_BSPWM CFLAGS += -std=c99 -Iinclude -pedantic -Wall -flto -O2 `pkg-config --cflags pango pangocairo libconfig gdk-pixbuf-2.0 alsa` LDFLAGS += -flto -O2 -LDLIBS += -liw -lxcb -lpthread -lxcb-randr -lxcb-ewmh -lxcb-icccm -lm `pkg-config --libs pango pangocairo libconfig gdk-pixbuf-2.0 alsa` +LDLIBS += -liw -lxcb -lpthread -lxcb-randr -lxcb-ewmh -lxcb-icccm -lm `pkg-config --libs pango pangocairo libconfig gdk-pixbuf-2.0 alsa playerctl-1.0` PROGRAM := yabar DOCS := $(PROGRAM).1 PREFIX ?= /usr diff --git a/doc/yabar.1.asciidoc b/doc/yabar.1.asciidoc index 2ae18af..6d034c3 100644 --- a/doc/yabar.1.asciidoc +++ b/doc/yabar.1.asciidoc @@ -328,6 +328,12 @@ internal-option2: "    "; # icons to indicate quarter, half, internal-suffix: "%"; ---- +* *YABAR_SONG* - *Current Song*: Uses 'playerctl' to retrieve the name of the currently played song. Example: +---- +exec: "YABAR_SONG"; +internal-option1: "spotify"; +---- + * *YABAR_VOLUME* - *Volume*: Uses ALSA to display sound volume in percentage. Example: ---- exec: "YABAR_VOLUME"; diff --git a/examples/example.config b/examples/example.config index 6b409ad..19d6958 100644 --- a/examples/example.config +++ b/examples/example.config @@ -199,4 +199,10 @@ topbar:{ foreground-color-rgb:0x92D8F0; underline-color-rgb:0xc0b929; } + song:{ + exec: "YABAR_SONG"; + fixed-size: 200; + type: "periodic"; + internal-option1: "spotify"; + } } diff --git a/shell.nix b/shell.nix index d3deab9..d0f8f53 100644 --- a/shell.nix +++ b/shell.nix @@ -4,6 +4,6 @@ with import {}; stdenv.mkDerivation { buildInputs = [ cairo gdk_pixbuf libconfig pango pkgconfig xorg.xcbutilwm docbook_xsl - alsaLib wirelesstools asciidoc libxslt makeWrapper libxml2 + alsaLib wirelesstools asciidoc libxslt makeWrapper libxml2 playerctl ]; } diff --git a/src/intern_blks/ya_intern.c b/src/intern_blks/ya_intern.c index 750c9cb..92e074c 100644 --- a/src/intern_blks/ya_intern.c +++ b/src/intern_blks/ya_intern.c @@ -22,8 +22,10 @@ void ya_int_battery(ya_block_t *blk); void ya_int_volume(ya_block_t *blk); void ya_int_wifi(ya_block_t *blk); void ya_int_diskspace(ya_block_t *blk); +void ya_int_song(ya_block_t *blk); struct reserved_blk ya_reserved_blks[YA_INTERNAL_LEN] = { + {"YABAR_SONG", ya_int_song}, {"YABAR_DATE", ya_int_date}, {"YABAR_UPTIME", ya_int_uptime}, {"YABAR_THERMAL", ya_int_thermal}, @@ -129,6 +131,66 @@ __attribute__ ((gnu_inline)) inline void ya_setup_prefix_suffix(ya_block_t *blk, } } +#include +#define CHECK_PLAYER_ERROR(PREFIX) \ + if (PREFIX) \ + ya_block_error(blk, "Player error!"); + +#define PRINT_PAUSED_MSG() \ + sprintf(startstr,"%s",blk->internal->option[2]); + +void ya_int_song(ya_block_t *blk) { + char *startstr = blk->buf; + size_t prflen = 0,suflen = 0; + ya_setup_prefix_suffix(blk, &prflen, &suflen, &startstr); + + GError *e_tmp, *e_title, *e_artist; + PlayerctlPlayer *player; + gchar *s; + + if (blk->internal->option[0]==NULL) + ya_block_error(blk, "Please set option0 for playerctl (e.g. spotify)!"); + if (blk->internal->option[1]==NULL) + blk->internal->option[1] = " - "; + if (blk->internal->option[2]==NULL) + blk->internal->option[2] = "Paused"; + + while (1) { + player = playerctl_player_new(blk->internal->option[0], &e_tmp); + g_object_get(player, "status", &s, NULL); + + if (s == NULL) { + PRINT_PAUSED_MSG(); + continue; + } + if (strcmp("Playing", s) == 0) { + CHECK_PLAYER_ERROR(e_tmp); + + sprintf( + startstr, + "%s %s %s", + playerctl_player_get_artist(player, &e_artist), + blk->internal->option[1], + playerctl_player_get_title(player, &e_title) + ); + + CHECK_PLAYER_ERROR(e_title); + CHECK_PLAYER_ERROR(e_artist); + } else { + PRINT_PAUSED_MSG(); + } + + if(suflen) + strcat(blk->buf, blk->internal->suffix); + + g_free(s); + g_object_unref(player); + + ya_draw_pango_text(blk); + sleep(blk->sleep); + } +} + #include void ya_int_date(ya_block_t * blk) { time_t rawtime; From 9809dcd07d1931d1ef9c63dac65cc9012245c5d2 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Tue, 3 Oct 2017 20:16:22 +0200 Subject: [PATCH 3/4] Make `playerctl` support optional with a compiler flag As Ubuntu doesn't provide `playerctl` by default, it's better to make this optional. Furthermore another build with playerctl support has been added to the CI matrix. --- .travis.yml | 20 ++++++++++++++++++++ Makefile | 10 +++++++++- src/intern_blks/ya_intern.c | 7 +++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d4a4cab..ba0ba15 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,26 @@ sudo: false dist: trusty matrix: include: + - script: make yabar + compiler: gcc + language: c + sudo: required + env: CPPFLAGS=-DOLD_LIBCONFIG PLAYERCTL=1 + addons: + apt: + packages: + - libxcb-randr0-dev + - libconfig-dev + - libcairo2-dev + - libpango1.0-dev + - libxcb-ewmh-dev + - libxcb-icccm4-dev + - libasound2-dev + - libiw-dev + - wget + before_install: + - wget https://github.com/acrisci/playerctl/releases/download/v0.5.0/playerctl-0.5.0_amd64.deb -O playerctl.deb + - sudo dpkg -i playerctl.deb - script: make yabar compiler: gcc language: c diff --git a/Makefile b/Makefile index 9a78be4..8a9df29 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,16 @@ CPPFLAGS += -DVERSION=\"$(VERSION)\" -D_POSIX_C_SOURCE=199309L -DYA_INTERNAL -DY -DYA_ENV_VARS -DYA_INTERNAL_EWMH -DYA_ICON -DYA_NOWIN_COL -DYA_MUTEX -DYA_VAR_WIDTH \ -DYA_BSPWM CFLAGS += -std=c99 -Iinclude -pedantic -Wall -flto -O2 `pkg-config --cflags pango pangocairo libconfig gdk-pixbuf-2.0 alsa` + +DEPS += pango pangocairo libconfig gdk-pixbuf-2.0 alsa +ifdef PLAYERCTL +CFLAGS += -DPLAYERCTL +CPPFLAGS += -DPLAYERCTL +DEPS += playerctl-1.0 +endif + LDFLAGS += -flto -O2 -LDLIBS += -liw -lxcb -lpthread -lxcb-randr -lxcb-ewmh -lxcb-icccm -lm `pkg-config --libs pango pangocairo libconfig gdk-pixbuf-2.0 alsa playerctl-1.0` +LDLIBS += -liw -lxcb -lpthread -lxcb-randr -lxcb-ewmh -lxcb-icccm -lm `pkg-config --libs $(DEPS)` PROGRAM := yabar DOCS := $(PROGRAM).1 PREFIX ?= /usr diff --git a/src/intern_blks/ya_intern.c b/src/intern_blks/ya_intern.c index 92e074c..a0c0893 100644 --- a/src/intern_blks/ya_intern.c +++ b/src/intern_blks/ya_intern.c @@ -22,10 +22,15 @@ void ya_int_battery(ya_block_t *blk); void ya_int_volume(ya_block_t *blk); void ya_int_wifi(ya_block_t *blk); void ya_int_diskspace(ya_block_t *blk); + +#ifdef PLAYERCTL void ya_int_song(ya_block_t *blk); +#endif struct reserved_blk ya_reserved_blks[YA_INTERNAL_LEN] = { +#ifdef PLAYERCTL {"YABAR_SONG", ya_int_song}, +#endif {"YABAR_DATE", ya_int_date}, {"YABAR_UPTIME", ya_int_uptime}, {"YABAR_THERMAL", ya_int_thermal}, @@ -131,6 +136,7 @@ __attribute__ ((gnu_inline)) inline void ya_setup_prefix_suffix(ya_block_t *blk, } } +#ifdef PLAYERCTL #include #define CHECK_PLAYER_ERROR(PREFIX) \ if (PREFIX) \ @@ -190,6 +196,7 @@ void ya_int_song(ya_block_t *blk) { sleep(blk->sleep); } } +#endif #include void ya_int_date(ya_block_t * blk) { From bd4d6c2fd71ed4b3a7872ea0e0621d130735d4c9 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Thu, 5 Oct 2017 19:26:48 +0200 Subject: [PATCH 4/4] Fix enum size in `yabar.h` to fix compiler warning --- include/yabar.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/include/yabar.h b/include/yabar.h index 26ace42..bd91161 100644 --- a/include/yabar.h +++ b/include/yabar.h @@ -119,10 +119,18 @@ enum { #ifdef YA_INTERNAL_EWMH +#ifdef PLAYERCTL +#define YA_INTERNAL_LEN 17 +#else #define YA_INTERNAL_LEN 16 +#endif +#else +#ifdef PLAYERCTL +#define YA_INTERNAL_LEN 15 #else #define YA_INTERNAL_LEN 14 #endif +#endif enum { YA_INT_DATE = 0, YA_INT_UPTIME, @@ -139,7 +147,8 @@ enum { YA_INT_WIFI, YA_INT_DISKSPACE, YA_INT_TITLE, - YA_INT_WORKSPACE + YA_INT_WORKSPACE, + YA_INT_SONG }; #define NOT_INHERIT_BAR(bar) (((bar)->attr & BARA_INHERIT)==0)