Skip to content
Permalink
Browse files

Turn lights off when desktop is idle

  • Loading branch information
tatokis committed Jan 3, 2020
1 parent 528858b commit b63c3f965d5aa858be1d16d97d8e035471dc4cb4
@@ -102,10 +102,11 @@ cmake_dependent_option(WITH_SNAKE "Build with 'Snake' animation." ON "WITH
cmake_dependent_option(WITH_PIPE "Build with 'Pipe' animation." ON "WITH_ANIMATIONS;WITH_GUI" OFF)

if (LINUX)
cmake_dependent_option(WITH_MVIZ "Build with music visualizer." ON "WITH_ANIMATIONS;WITH_GUI" OFF)
option(USE_PORTAUDIO "Use portaudio for music visualizer." OFF)
cmake_dependent_option(WITH_MVIZ "Build with music visualizer." ON "WITH_ANIMATIONS;WITH_GUI" OFF)
cmake_dependent_option(USE_XCB "Build with features that require XCB." ON "WITH_GUI" OFF)
option(USE_PORTAUDIO "Use portaudio for music visualizer." OFF)
else ()
cmake_dependent_option(WITH_MVIZ "Build with music visualizer." OFF "WITH_ANIMATIONS;WITH_GUI" OFF)
cmake_dependent_option(WITH_MVIZ "Build with music visualizer." OFF "WITH_ANIMATIONS;WITH_GUI" OFF)
set(USE_PORTAUDIO ON)
endif ()
# Options: daemon
@@ -98,6 +98,7 @@ elseif (LINUX)
endif ()
endif ()
find_package(X11 REQUIRED)
find_package(Qt5 5.2.0 COMPONENTS X11Extras)
endif ()

# Automatically handle MOC, UIC and RCC
@@ -131,6 +132,7 @@ if (MACOS OR LINUX)
gradientbutton.cpp
gradientdialog.cpp
gradientdialogwidget.cpp
idletimer.cpp
kbanim.cpp
kbanimwidget.cpp
kbbind.cpp
@@ -175,6 +177,7 @@ if (MACOS OR LINUX)
gradientbutton.h
gradientdialog.h
gradientdialogwidget.h
idletimer.h
kbanim.h
kbanimwidget.h
kbbind.h
@@ -229,13 +232,36 @@ if (MACOS)
media_mac.m)
elseif (LINUX)
find_package(PulseAudio)
if (${PULSEAUDIO_FOUND})
if (PULSEAUDIO_FOUND)
target_compile_definitions(
ckb-next
PRIVATE
USE_LIBPULSE)
endif ()

if (USE_XCB)
find_package(PkgConfig REQUIRED)
pkg_check_modules(XCB xcb)
pkg_check_modules(XCB_EWMH xcb-ewmh)
pkg_check_modules(XCB_SCREENSAVER xcb-screensaver)

if(XCB_SCREENSAVER_FOUND AND Qt5X11Extras_FOUND)
target_compile_definitions(
ckb-next
PRIVATE
USE_XCB_SCREENSAVER)
else()
message(FATAL_ERROR "XCB-Screensaver or Qt5 X11Extras was not found. Either install them or pass -DUSE_XCB=0 to disable idle detection.")
endif()
if(XCB_EWMH_FOUND)
target_compile_definitions(
ckb-next
PRIVATE
USE_XCB_EWMH)
else()
message(FATAL_ERROR "XCB-EWMH was not found. Either install it or pass -DUSE_XCB=0 to disable active window detection.")
endif()
endif()
target_sources(
ckb-next
PRIVATE
@@ -434,20 +460,15 @@ if(MACOS)
"${FOUNDATION_LIBRARY}"
"${AUDIOTOOLBOX_LIBRARY}")
elseif (LINUX)
if(${PULSEAUDIO_FOUND})
target_link_libraries(
ckb-next
PRIVATE
"${X11_LIBRARIES}"
"${Appindicator_LIBRARIES}"
"${PULSEAUDIO_LIBRARIES}")
else()
target_link_libraries(
ckb-next
PRIVATE
"${X11_LIBRARIES}"
"${Appindicator_LIBRARIES}")
endif()
target_link_libraries(
ckb-next
PRIVATE
"${X11_LIBRARIES}"
"${Appindicator_LIBRARIES}"
"${PULSEAUDIO_LIBRARIES}"
"${XCB_EWMH_LIBRARIES}"
"${XCB_SCREENSAVER_LIBRARIES}"
Qt5::X11Extras)
endif()

if (WITH_SHIPPED_QUAZIP)
@@ -4,6 +4,8 @@
#include "mainwindow.h"
#include "ckbsettings.h"
#include "animdetailsdialog.h"
#include "kbmanager.h"
#include "idletimer.h"

// KbLight
static int lastSharedDimming = -2;
@@ -75,8 +77,24 @@ ExtraSettingsWidget::ExtraSettingsWidget(QWidget *parent) :

ui->previewBox->setChecked(settings.value("DisablePreviewOnFocusLoss", true).toBool());

#ifndef Q_OS_LINUX
#if defined(Q_OS_LINUX) && defined(USE_XCB_SCREENSAVER)
// We need to explicitly disable this if there's a wayland session.
// If not, the idle timer will only count when there's activity inside XWayland windows.
if(IdleTimer::isWayland()){
QString notSupported(tr("This feature is not supported under Wayland"));
ui->timerBox->setToolTip(notSupported);
ui->timerMinBox->setToolTip(notSupported);
ui->timerBox->setEnabled(false);
ui->timerMinBox->setEnabled(false);
} else {
ui->timerBox->setChecked(settings.value("IdleTimerEnable", true).toBool());
ui->timerMinBox->setEnabled(ui->timerBox->isChecked());
}
ui->timerMinBox->setValue(settings.value("IdleTimerDuration", 5).toInt());
#else
ui->scrollWarningLabel->hide();
ui->timerBox->hide();
ui->timerMinBox->hide();
#endif
}

@@ -159,14 +177,24 @@ void ExtraSettingsWidget::on_startDelayBox_clicked(bool checked){
CkbSettings::set("Program/StartDelay", checked);
}

void ExtraSettingsWidget::on_previewBox_clicked(bool checked)
{
void ExtraSettingsWidget::on_previewBox_clicked(bool checked){
CkbSettings::set("Program/DisablePreviewOnFocusLoss", checked);
}

void ExtraSettingsWidget::on_detailsBtn_clicked()
{
void ExtraSettingsWidget::on_detailsBtn_clicked(){
AnimDetailsDialog* dlg = new AnimDetailsDialog(this);
dlg->setAttribute(Qt::WA_DeleteOnClose, true);
dlg->exec();
}

void ExtraSettingsWidget::on_timerBox_clicked(bool checked){
ui->timerMinBox->setEnabled(checked);
CkbSettings::set("Program/IdleTimerEnable", checked);
KbManager::setIdleTimer(checked);
}

void ExtraSettingsWidget::on_timerMinBox_editingFinished(){
CkbSettings::set("Program/IdleTimerDuration", ui->timerMinBox->value());
KbManager::setIdleTimer(false);
KbManager::setIdleTimer(true);
}
@@ -32,6 +32,10 @@ private slots:

void on_detailsBtn_clicked();

void on_timerBox_clicked(bool checked);

void on_timerMinBox_editingFinished();

private:
Ui::ExtraSettingsWidget *ui;
};

0 comments on commit b63c3f9

Please sign in to comment.
You can’t perform that action at this time.