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
5 changes: 5 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
UseTab: Always
IndentWidth: 4
TabWidth: 4
ColumnLimit: 80
AllowShortFunctionsOnASingleLine: None
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

[*.{h,c,hpp,cpp}]
indent_style = tab
indent_size = 4
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ dkms.conf
SwayAudioIdleInhibit
sway-audio-idle-inhibit-git*
pkg

!build-scripts/sway-audio-idle-inhibit-git.rpkg.spec
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# SwayAudioIdleInhibit

Prevents swayidle from sleeping while any application is outputting or
receiving audio. Should work with all Wayland desktops that support the
`zwp_idle_inhibit_manager_v1` protocol but only tested in Sway
Prevents swayidle/hypridle from sleeping while any application is outputting or
receiving audio. Requires systemd/elogind inhibit support.

This only works for Pulseaudio / Pipewire Pulse

Expand All @@ -14,8 +13,13 @@ The package is available on the [AUR](https://aur.archlinux.org/packages/sway-au
Other:

```zsh
meson build
ninja -C build
# Can compile to use systemd or elogind
# systemd (default)
meson setup build -Dlogind-provider=systemd
# or elogind for systemd-less systems
meson setup build -Dlogind-provider=elogind

meson compile -C build
meson install -C build
```

Expand Down Expand Up @@ -60,7 +64,7 @@ or `modules-right` list.

*Note: The FontAwesome font is used for the icons below*

```
```json
"custom/audio_idle_inhibitor": {
"format": "{icon}",
"exec": "sway-audio-idle-inhibit --dry-print-both-waybar",
Expand All @@ -74,4 +78,3 @@ or `modules-right` list.
}
},
```

7 changes: 3 additions & 4 deletions PKGBUILD → build-scripts/PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Maintainer: Erik Reider <erik.reider@protonmail.com>
pkgname=sway-audio-idle-inhibit-git
_ver=0.1.1
pkgver=0.1.1.r31.e9cb7d6
_ver=0.2.0
pkgver=$_ver.r53.e903b34
pkgrel=1
pkgdesc="Prevents swayidle from sleeping while any application is outputting or receiving audio"
_pkgfoldername=SwayAudioIdleInhibit
Expand All @@ -12,7 +12,7 @@ arch=(
'armv7h' # ARM v7 hardfloat
)
license=(GPL)
depends=("wayland>=1.14.91" "wayland-protocols" "libpulse")
depends=("systemd-libs" "libpulse")
makedepends=(gcc meson git)
optdepends=("swaync-git" "swaysettings-git")
source=("git+$url")
Expand All @@ -26,7 +26,6 @@ pkgver() {
prepare() {
cd $_pkgfoldername
git checkout main
git pull
}

build() {
Expand Down
43 changes: 43 additions & 0 deletions build-scripts/sway-audio-idle-inhibit-git.rpkg.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# vim: syntax=spec
Name: sway-audio-idle-inhibit-git
Version: {{{ git_repo_release lead="$(git describe --tags --abbrev=0)" }}}
Release: {{{ echo -n "$(git rev-list --all --count)" }}}%{?dist}
Summary: Prevents swayidle from sleeping while any application is outputting or receiving audio.
License: GPLv3
URL: https://github.com/ErikReider/SwayAudioIdleInhibit
VCS: {{{ git_repo_vcs }}}
Source: {{{ git_repo_pack }}}

BuildRequires: meson >= 0.60.0
BuildRequires: git
BuildRequires: gcc-c++

BuildRequires: pkgconfig(libpulse)
BuildRequires: pkgconfig(libsystemd)

%{?systemd_requires}

%description
Prevents swayidle from sleeping while any application is outputting or receiving audio.
Should work with all Wayland desktops that support the zwp_idle_inhibit_manager_v1 protocol but only tested in Sway

This only works for Pulseaudio / Pipewire Pulse

%prep
{{{ git_repo_setup_macro }}}

%build
%meson
%meson_build

%install
%meson_install

%files
%doc README.md
%{_bindir}/sway-audio-idle-inhibit
%license LICENSE

# Changelog will be empty until you make first annotated Git tag.
%changelog
{{{ git_repo_changelog }}}
10 changes: 4 additions & 6 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ Rules-Requires-Root: no
Build-Depends:
meson,
libpulse-dev,
libsystemd-dev,
build-essential,
wayland-protocols,
libwayland-dev,
debhelper-compat (= 13),
Standards-Version: 4.6.1
Homepage: https://github.com/ErikReider/SwayAudioIdleInhibit
Expand All @@ -18,7 +17,6 @@ Architecture: any
Depends:
${misc:Depends},
libpulse0,
wayland-protocols,
sway
Description: Prevents swayidle from sleeping while
any application is outputting or receiving audio
libsystemd0,
Description: Prevents system from idling while
an audio source or audio sink is active
61 changes: 30 additions & 31 deletions include/data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,55 @@
#include <pulse/context.h>
#include <pulse/thread-mainloop.h>

#include <iostream>

#include "idle.hpp"

using namespace std;

#define MAX_IGNORED_SOURCE_OUTPUTS 100

enum SubscriptionType {
SUBSCRIPTION_TYPE_IDLE,
SUBSCRIPTION_TYPE_DRY_BOTH,
SUBSCRIPTION_TYPE_DRY_BOTH_WAYBAR,
SUBSCRIPTION_TYPE_DRY_SINK,
SUBSCRIPTION_TYPE_DRY_SOURCE,
SUBSCRIPTION_TYPE_IDLE,
SUBSCRIPTION_TYPE_DRY_BOTH,
SUBSCRIPTION_TYPE_DRY_BOTH_WAYBAR,
SUBSCRIPTION_TYPE_DRY_SINK,
SUBSCRIPTION_TYPE_DRY_SOURCE,
};
enum EventType {
EVENT_TYPE_IDLE,
EVENT_TYPE_DRY_BOTH,
EVENT_TYPE_DRY_SINK,
EVENT_TYPE_DRY_SOURCE,
EVENT_TYPE_NONE,
EVENT_TYPE_IDLE,
EVENT_TYPE_DRY_BOTH,
EVENT_TYPE_DRY_SINK,
EVENT_TYPE_DRY_SOURCE,
EVENT_TYPE_NONE,
};

struct Data {
pa_threaded_mainloop *mainloop;
pa_mainloop_api *mainloop_api;
pa_context *context;
pa_threaded_mainloop *mainloop;
pa_mainloop_api *mainloop_api;
pa_context *context;

EventType eventCalled = EVENT_TYPE_NONE;
bool activeSource = false;
bool activeSink = false;
EventType eventCalled = EVENT_TYPE_NONE;
bool activeSource = false;
bool activeSink = false;

SubscriptionType subscriptionType;
pa_subscription_mask_t pa_subscriptionType;
SubscriptionType subscriptionType;
pa_subscription_mask_t pa_subscriptionType;

char **ignoredSourceOutputs;
char **ignoredSourceOutputs;

Idle *idle = NULL;
Idle *idle = NULL;

bool failed = false;
bool failed = false;

Data(pa_threaded_mainloop *mainloop, pa_mainloop_api *mainloop_api,
SubscriptionType subscriptionType,
pa_subscription_mask_t pa_subscriptionType, EventType eventType, char **ignoredSourceOutputs);
Data(pa_threaded_mainloop *mainloop, pa_mainloop_api *mainloop_api,
SubscriptionType subscriptionType,
pa_subscription_mask_t pa_subscriptionType, EventType eventType,
char **ignoredSourceOutputs);

void quit(int returnValue = 0);
void quit(int returnValue = 0);

void handleAction();
void handleAction();

private:
void print(bool isRunning);
void printWayBar(bool activeSink, bool activeSource);
private:
void print(bool isRunning);
void printWayBar(bool activeSink, bool activeSource);
};
29 changes: 14 additions & 15 deletions include/idle.hpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
#pragma once

#include "idle-inhibit-unstable-v1-client-protocol.h"

using namespace std;
#if HAVE_SYSTEMD
#include <systemd/sd-bus.h>
#include <systemd/sd-login.h>
#elif HAVE_ELOGIND
#include <elogind/sd-bus.h>
#include <elogind/sd-login.h>
#endif

class Idle {
struct wl_compositor *compositor = NULL;
struct zwp_idle_inhibit_manager_v1 *wl_idle_inhibit_manager = NULL;
struct wl_surface *surface = NULL;
struct wl_display *display = NULL;
struct zwp_idle_inhibitor_v1 *idle = NULL;

static void global_add(void *data, struct wl_registry *registry,
uint32_t name, const char *interface, uint32_t);
struct sd_bus *bus = nullptr;
int fd = -1;

static void global_remove(void *, struct wl_registry *, uint32_t);
void block();
void release_block();

public:
Idle();
public:
Idle();

void update(bool isRunning);
void update(bool isRunning);
};
52 changes: 25 additions & 27 deletions include/pulse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,42 @@
#include <pulse/mainloop-api.h>
#include <pulse/pulseaudio.h>
#include <pulse/thread-mainloop.h>
#include <string.h>

#include <cstdlib>
#include <iostream>

#include "data.hpp"
#include "idle.hpp"

class Pulse {
public:
int init(SubscriptionType subscriptionType,
pa_subscription_mask_t pa_subscriptionType, EventType eventType, char **ignoredSourceOutputs);
public:
int init(SubscriptionType subscriptionType,
pa_subscription_mask_t pa_subscriptionType, EventType eventType,
char **ignoredSourceOutputs);

private:
static void sink_input_info_callback(pa_context *,
const pa_sink_input_info *i, int,
void *userdata);
private:
static void sink_input_info_callback(pa_context *,
const pa_sink_input_info *i, int,
void *userdata);

static void source_output_info_callback(pa_context *,
const pa_source_output_info *i, int,
void *userdata);
static void source_output_info_callback(pa_context *,
const pa_source_output_info *i, int,
void *userdata);

void getRunning(EventType eventType, Data *data, pa_context *context);
void getRunning(EventType eventType, Data *data, pa_context *context);

static void subscribe_callback(pa_context *,
pa_subscription_event_type_t type, uint32_t,
void *userdata);
static void subscribe_callback(pa_context *,
pa_subscription_event_type_t type, uint32_t,
void *userdata);

static void context_state_callback(pa_context *c, void *userdata);
static void context_state_callback(pa_context *c, void *userdata);

static pa_context *getContext(pa_threaded_mainloop *mainloop,
pa_mainloop_api *mainloop_api, void *userdata);
static pa_context *getContext(pa_threaded_mainloop *mainloop,
pa_mainloop_api *mainloop_api,
void *userdata);

void connect(pa_threaded_mainloop *mainloop, pa_mainloop_api *mainloop_api,
SubscriptionType subscriptionType,
pa_subscription_mask_t pa_subscriptionType, EventType eventType, char **ignoredSourceOutputs);
void connect(pa_threaded_mainloop *mainloop, pa_mainloop_api *mainloop_api,
SubscriptionType subscriptionType,
pa_subscription_mask_t pa_subscriptionType,
EventType eventType, char **ignoredSourceOutputs);

pa_threaded_mainloop *getMainLoop();
pa_threaded_mainloop *getMainLoop();

pa_mainloop_api *getMainLoopApi(pa_threaded_mainloop *mainloop);
pa_mainloop_api *getMainLoopApi(pa_threaded_mainloop *mainloop);
};
Loading