Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ addons:
- gcc-5
- i3-wm
- libasound2-dev
- libpulse-dev
- libcairo2-dev
- libiw-dev
- libmpdclient-dev
Expand Down
4 changes: 4 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function main

local build_ipc_msg="ON"
local enable_alsa="ON"
local enable_pulseaudio="ON"
local enable_i3="ON"
local enable_network="ON"
local enable_mpd="ON"
Expand All @@ -41,6 +42,8 @@ function main
[[ "${p^^}" != "Y" ]] && enable_i3="OFF"
read -r -p "$(msg "Include support for \"internal/volume\" (requires alsalib) ---------- [Y/n]: ")" -n 1 p && echo
[[ "${p^^}" != "Y" ]] && enable_alsa="OFF"
read -r -p "$(msg "Include support for \"internal/pulseaudio\" (requires libpulse) ----- [Y/n]: ")" -n 1 p && echo
[[ "${p^^}" != "Y" ]] && enable_pulseaudio="OFF"
read -r -p "$(msg "Include support for \"internal/network\" (requires wireless_tools) -- [Y/n]: ")" -n 1 p && echo
[[ "${p^^}" != "Y" ]] && enable_network="OFF"
read -r -p "$(msg "Include support for \"internal/mpd\" (requires libmpdclient) -------- [Y/n]: ")" -n 1 p && echo
Expand Down Expand Up @@ -68,6 +71,7 @@ function main
-DCMAKE_C_COMPILER="${cc}" \
-DCMAKE_CXX_COMPILER="${cxx}" \
-DENABLE_ALSA:BOOL="${enable_alsa}" \
-DENABLE_PULSEAUDIO:BOOL="${enable_pulseaudio}"\
-DENABLE_I3:BOOL="${enable_i3}" \
-DENABLE_MPD:BOOL="${enable_mpd}" \
-DENABLE_NETWORK:BOOL="${enable_network}" \
Expand Down
3 changes: 3 additions & 0 deletions cmake/02-opts.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ checklib(ENABLE_CURL "pkg-config" libcurl)
checklib(ENABLE_I3 "binary" i3)
checklib(ENABLE_MPD "pkg-config" libmpdclient)
checklib(ENABLE_NETWORK "cmake" Libiw)
checklib(ENABLE_PULSEAUDIO "pkg-config" libpulse)
checklib(ENABLE_PULSEAUDIO "binary" pulseaudio)
checklib(WITH_XRM "pkg-config" xcb-xrm)
checklib(WITH_XRANDR_MONITORS "pkg-config" "xcb-randr>=1.12")
checklib(WITH_XCURSOR "pkg-config" "xcb-cursor")
Expand All @@ -28,6 +30,7 @@ option(ENABLE_I3 "Enable i3 support" ON)
option(ENABLE_MPD "Enable mpd support" ON)
option(ENABLE_NETWORK "Enable network support" ON)
option(ENABLE_XKEYBOARD "Enable xkeyboard support" ON)
option(ENABLE_PULSEAUDIO "Enable PulseAudio support" ON)

option(WITH_XRANDR "xcb-randr support" ON)
option(WITH_XRANDR_MONITORS "xcb-randr monitor support" ON)
Expand Down
1 change: 1 addition & 0 deletions cmake/03-libs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ querylib(ENABLE_ALSA "pkg-config" alsa libs dirs)
querylib(ENABLE_CURL "pkg-config" libcurl libs dirs)
querylib(ENABLE_MPD "pkg-config" libmpdclient libs dirs)
querylib(ENABLE_NETWORK "cmake" Libiw libs dirs)
querylib(ENABLE_PULSEAUDIO "pkg-config" libpulse libs dirs)

querylib(WITH_XCOMPOSITE "pkg-config" xcb-composite libs dirs)
querylib(WITH_XDAMAGE "pkg-config" xcb-damage libs dirs)
Expand Down
1 change: 1 addition & 0 deletions cmake/05-summary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ colored_option(" curl" ENABLE_CURL)
colored_option(" i3" ENABLE_I3)
colored_option(" mpd" ENABLE_MPD)
colored_option(" network" ENABLE_NETWORK)
colored_option(" pulseaudio" ENABLE_PULSEAUDIO)

message(STATUS " X extensions:")
colored_option(" xcb-randr" WITH_XRANDR)
Expand Down
79 changes: 79 additions & 0 deletions include/adapters/pulseaudio.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#pragma once

#include <pulse/pulseaudio.h>
#include <queue>

#include "common.hpp"
#include "settings.hpp"
#include "errors.hpp"

#include "utils/math.hpp"
// fwd
struct pa_context;
struct pa_threaded_mainloop;
struct pa_cvolume;
typedef struct pa_context pa_context;
typedef struct pa_threaded_mainloop pa_threaded_mainloop;

POLYBAR_NS
class logger;

DEFINE_ERROR(pulseaudio_error);

class pulseaudio {
// events to add to our queue
enum class evtype { NEW = 0, CHANGE, REMOVE };
using queue = std::queue<evtype>;

public:
explicit pulseaudio(const logger& logger, string&& sink_name);
~pulseaudio();

pulseaudio(const pulseaudio& o) = delete;
pulseaudio& operator=(const pulseaudio& o) = delete;

const string& get_name();

bool wait();
int process_events();

int get_volume();
void set_volume(float percentage);
void inc_volume(int delta_perc);
void set_mute(bool mode);
void toggle_mute();
bool is_muted();

private:
void update_volume(pa_operation *o);
static void check_mute_callback(pa_context *context, const pa_sink_info *info, int eol, void *userdata);
static void get_sink_volume_callback(pa_context *context, const pa_sink_info *info, int is_last, void *userdata);
static void subscribe_callback(pa_context* context, pa_subscription_event_type_t t, uint32_t idx, void* userdata);
static void simple_callback(pa_context *context, int success, void *userdata);
static void get_default_sink_callback(pa_context *context, const pa_server_info *info, void *userdata);
static void sink_info_callback(pa_context *context, const pa_sink_info *info, int eol, void *userdata);
static void context_state_callback(pa_context *context, void *userdata);

inline void wait_loop(pa_operation *op, pa_threaded_mainloop *loop);

const logger& m_log;

// used for temporary callback results
int success{0};
pa_cvolume cv;
bool muted{false};
// default sink name
string def_s_name;

pa_context* m_context{nullptr};
pa_threaded_mainloop* m_mainloop{nullptr};

queue m_events;

// specified sink name
string spec_s_name;
string s_name;
uint32_t m_index{0};
};

POLYBAR_NS_END
7 changes: 6 additions & 1 deletion include/modules/meta/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,16 @@
#if ENABLE_ALSA
#include "modules/volume.hpp"
#endif
#if ENABLE_PULSEAUDIO
#include "modules/pulseaudio.hpp"
#endif
#if ENABLE_CURL
#include "modules/github.hpp"
#endif
#if ENABLE_XKEYBOARD
#include "modules/xkeyboard.hpp"
#endif
#if not(ENABLE_I3 && ENABLE_MPD && ENABLE_NETWORK && ENABLE_ALSA && ENABLE_CURL && ENABLE_XKEYBOARD)
#if not(ENABLE_I3 && ENABLE_MPD && ENABLE_NETWORK && ENABLE_ALSA && ENABLE_PULSEAUDIO && ENABLE_CURL && ENABLE_XKEYBOARD)
#include "modules/unsupported.hpp"
#endif

Expand Down Expand Up @@ -74,6 +77,8 @@ namespace {
return new mpd_module(bar, move(module_name));
} else if (name == "internal/volume") {
return new volume_module(bar, move(module_name));
} else if (name == "internal/pulseaudio") {
return new pulseaudio_module(bar, move(module_name));
} else if (name == "internal/network") {
return new network_module(bar, move(module_name));
#if DEBUG
Expand Down
55 changes: 55 additions & 0 deletions include/modules/pulseaudio.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#pragma once

#include "settings.hpp"
#include "modules/meta/event_module.hpp"
#include "modules/meta/input_handler.hpp"

POLYBAR_NS

// fwd
class pulseaudio;

namespace modules {
using pulseaudio_t = shared_ptr<pulseaudio>;

class pulseaudio_module : public event_module<pulseaudio_module>, public input_handler {
public:
explicit pulseaudio_module(const bar_settings&, string);

void teardown();
bool has_event();
bool update();
string get_format() const;
string get_output();
bool build(builder* builder, const string& tag) const;

protected:
bool input(string&& cmd);

private:
static constexpr auto FORMAT_VOLUME = "format-volume";
static constexpr auto FORMAT_MUTED = "format-muted";

static constexpr auto TAG_RAMP_VOLUME = "<ramp-volume>";
static constexpr auto TAG_BAR_VOLUME = "<bar-volume>";
static constexpr auto TAG_LABEL_VOLUME = "<label-volume>";
static constexpr auto TAG_LABEL_MUTED = "<label-muted>";

static constexpr auto EVENT_PREFIX = "vol";
static constexpr auto EVENT_VOLUME_UP = "volup";
static constexpr auto EVENT_VOLUME_DOWN = "voldown";
static constexpr auto EVENT_TOGGLE_MUTE = "volmute";

progressbar_t m_bar_volume;
ramp_t m_ramp_volume;
label_t m_label_volume;
label_t m_label_muted;

pulseaudio_t m_pulseaudio;

atomic<bool> m_muted{false};
atomic<int> m_volume{0};
};
}

POLYBAR_NS_END
5 changes: 4 additions & 1 deletion include/modules/unsupported.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#if ENABLE_I3 && ENABLE_MPD && ENABLE_NETWORK && ENABLE_ALSA && ENABLE_CURL && ENABLE_XKEYBOARD
#if ENABLE_I3 && ENABLE_MPD && ENABLE_NETWORK && ENABLE_ALSA && ENABLE_PULSEAUDIO && ENABLE_CURL && ENABLE_XKEYBOARD
#error "Support has been enabled for all optional modules"
#endif

Expand Down Expand Up @@ -43,6 +43,9 @@ namespace modules {
#if not ENABLE_ALSA
DEFINE_UNSUPPORTED_MODULE(volume_module, "internal/volume");
#endif
#if not ENABLE_PULSEAUDIO
DEFINE_UNSUPPORTED_MODULE(pulseaudio_module, "internal/pulseaudio");
#endif
#if not ENABLE_CURL
DEFINE_UNSUPPORTED_MODULE(github_module, "internal/github");
#endif
Expand Down
6 changes: 4 additions & 2 deletions include/settings.hpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#cmakedefine01 ENABLE_NETWORK
#cmakedefine01 ENABLE_I3
#cmakedefine01 ENABLE_CURL
#cmakedefine01 ENABLE_PULSEAUDIO

#cmakedefine01 WITH_XRANDR
#cmakedefine01 WITH_XRENDER
Expand Down Expand Up @@ -99,12 +100,13 @@ const auto version_details = [](const std::vector<std::string>& args) {
// clang-format off
const auto print_build_info = [](bool extended = false) {
printf("%s %s\n\n", APP_NAME, APP_VERSION);
printf("Features: %calsa %ccurl %ci3 %cmpd %cnetwork\n",
printf("Features: %calsa %ccurl %ci3 %cmpd %cnetwork %cpulseaudio\n",
(ENABLE_ALSA ? '+' : '-'),
(ENABLE_CURL ? '+' : '-'),
(ENABLE_I3 ? '+' : '-'),
(ENABLE_MPD ? '+' : '-'),
(ENABLE_NETWORK ? '+' : '-'));
(ENABLE_NETWORK ? '+' : '-'),
(ENABLE_PULSEAUDIO ? '+' : '-'));
if (extended) {
printf("\n");
printf("X extensions: %crandr (%cmonitors) %crender %cdamage %csync %ccomposite %cxkb %cxrm %cxcursor\n",
Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ if(NOT ENABLE_I3)
list(REMOVE_ITEM files modules/i3.cpp)
list(REMOVE_ITEM files utils/i3.cpp)
endif()
if(NOT ENABLE_PULSEAUDIO)
list(REMOVE_ITEM files modules/pulseaudio.cpp)
list(REMOVE_ITEM files adapters/pulseaudio.cpp)
endif()
if(NOT WITH_XRANDR)
list(REMOVE_ITEM files x11/extensions/randr.cpp)
endif()
Expand Down
Loading