• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

phuhl/linux_notification_center: A notification daemon/center for linux

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

phuhl/linux_notification_center

开源软件地址(OpenSource Url):

https://github.com/phuhl/linux_notification_center

开源编程语言(OpenSource Language):

Haskell 90.3%

开源软件介绍(OpenSource Introduction):

https://github.com/phuhl/linux_notification_center/workflows/CI/badge.svg?branch=master

Linux Notification Center

A haskell-written notification center for users that like a desktop with style…

Take part in the discussion on our new discussion board!

Features

The notification center receives notifications via DBUS (like any notification daemon) and shows them in the upper right corner of the screen. The notification (if not specified in the notification otherwise) will also be shown in the notification center even after the notification disappeared by itself. The notifications can be clicked to make them disappear.

Notifications can be replaced by the use of the replaces-id feature of the notification specification.

The notification center can (optionally) show user-specified buttons in the bottom that can be in two states (highlighted/not highlighted) and that can run customizable shell commands.

Screenshots

Some applications, notification: README.org.img/org_20200223_193450_1en7sh.jpg

Notification Center opened: README.org.img/org_20200223_193345_VhlbOf.jpg

Link, Markup, Progressbar, and Action support: README.org.img/org_20201220_000601_9V037T.jpg

Usage

To start it:

> deadd-notification-center

Toggle between hidden and shown state of the notification center:

kill -s USR1 $(pidof deadd-notification-center)

Set the state of a user defined button (in this example the first button, which has id 0):

# turn highlighting on
notify-send.py a --hint boolean:deadd-notification-center:true \
               int:id:0 boolean:state:true type:string:buttons

# turn highlighting off
notify-send.py a --hint boolean:deadd-notification-center:true \
               int:id:0 boolean:state:false type:string:buttons

This snippet uses notify-send.py, an improved version of libnotify (notify-send).

Clear all notifications

# within the notification center
notify-send.py a --hint boolean:deadd-notification-center:true \
               string:type:clearInCenter

# popups
notify-send.py a --hint boolean:deadd-notification-center:true \
               string:type:clearPopups

Pause/Unpause popup notifications

# pause popup notifications
notify-send.py a --hint boolean:deadd-notification-center:true \
                 string:type:pausePopups

# unpause popup notifications
notify-send.py a --hint boolean:deadd-notification-center:true \
                 string:type:unpausePopups

Reload CSS Styling file

notify-send.py a --hint boolean:deadd-notification-center:true \
                 string:type:reloadStyle

Send notifications that only show up in the notification center but do not produce a popup:

notify-send.py "Does not pop up" -t 1

Supported hints and features

Action buttons with gtk icons

notify-send.py "And buttons" "Do you like buttons?" \
               --hint boolean:action-icons:true \
               --action yes:face-cool no:face-sick  

Notification images by gtk icon

notify-send.py "Icons are" "COOL" \
               --hint string:image-path:face-cool

Notification images by file

notify-send.py "Images are" "COOL" \
               --hint string:image-path:file://path/to/image/from/root.png

Notification with progress bar

notify-send.py "This notification has a progressbar" "33%" \
                         --hint int:has-percentage:33)
#or
notify-send.py "This notification has a progressbar" "33%" \
                         --hint int:value:33)

Notification with slider

notify-send.py "This notification has a slider" "33%" \
                         --hint int:has-percentage:33
                         --action changeValue:abc)

Example: Brightness indicator

This snippet can be used to produce a brightness-indicator. It requires the notify-send.py script.

#!/bin/bash

if [ "$1" == "inc" ]; then
    xbacklight -inc 5
fi

if [ "$1" == "dec" ]; then
    xbacklight -lower 5
fi

BRIGHTNESS=$(xbacklight -get)
NOTI_ID=$(notify-send.py "Bildschirmhelligkeit" "$BRIGHTNESS/100" \
                         --hint string:image-path:video-display boolean:transient:true \
                                int:has-percentage:$BRIGHTNESS \
                         --replaces-process "brightness-popup")

Example: Volume indicator

This snippet can be used to produce a volume-indicator. It requires the notify-send.py script.

#!/bin/bash

if [ "$1" == "inc" ]; then
   amixer -q sset Master 5%+
fi

if [ "$1" == "dec" ]; then
   amixer -q sset Master 5%-
fi

if [ "$1" == "mute" ]; then
   amixer -q sset Master toggle
fi


AMIXER=$(amixer sget Master)
VOLUME=$(echo $AMIXER | grep 'Right:' | awk -F'[][]' '{ print $2 }' | tr -d "%")
MUTE=$(echo $AMIXER | grep -o '\[off\]' | tail -n 1)
if [ "$VOLUME" -le 20 ]; then
    ICON=audio-volume-low
else if [ "$VOLUME" -le 60 ]; then
         ICON=audio-volume-medium
     else 
         ICON=audio-volume-high
     fi
fi
if [ "$MUTE" == "[off]" ]; then
    ICON=audio-volume-muted
fi 



NOTI_ID=$(notify-send.py "Lautstärke" "$VOLUME/100" \
                         --hint string:image-path:$ICON boolean:transient:true \
                                int:has-percentage:$VOLUME \
                         --replaces-process "volume-popup")

Install

Install from the AUR for Arch: deadd-notification-center.

OR

If you want to spare yourself the hassle of the build time there is a binary package available: deadd-notification-center-bin.

OR

If you don’t want to wait for me to publish the next stable release: Use the new AUR git-package.

deadd-notification-center-git.

OR

On Ubuntu, Debian, everything… Replace 1.7.2 with the current-most release from the release section.

Manually install the dependencies (exact names might differ in your distribution):

  • gtk3
  • gobject-introspection-runtime
tar -xvzf linux_notification_center-1.7.2.tar.gz
cd linux_notification_center-1.7.2
wget https://github.com/phuhl/linux_notification_center/releases/download/1.7.2/deadd-notification-center
mkdir -p .out
mv deadd-notification-center .out
sudo make install

OR

Dependencies:

  • stack
  • cairo
  • pango
  • gobject-introspection
  • gtk3
make
sudo make install

Configuration

NOTE: Some styling config has moved. More infos in this file: updateyourconfig2021.org

No configuration is necessary, the notification center comes with sensible defaults™.

All colors and sizes are customizable, as well as the default timeout for notifications and the optional buttons in the notification center. Below are possible configurable options shown. The configuration file must be located at ~/.config/deadd/deadd.conf (or, if configured differently on your system: ${XDG_CONFIG_HOME}/deadd/deadd.conf).

Additionally, a deadd.css will be loaded from the same folder. It contains the styling of the notification center. You can load changes from the deadd.css file by using the command described in the section “Usage”.

[notification-center]

# Hide the notification center when the mouse leaves the window
hideOnMouseLeave = True

# Margin at the top of the notification center in pixels. This can be
# used to avoid overlap between the notification center and bars such
# as polybar or i3blocks.
marginTop = 0

# Margin at the bottom of the notification center in pixels.
marginBottom = 0

# Margin to the right of the notification center in pixels.
marginRight = 0


# Width of the notification center in pixels. 
width = 500

# Monitor on which the notification center will be printed.
monitor = 0

# If true, the notification center will open on the screen, on which the
# mouse is
followMouse = false


# (Optional) Command to run at startup.  This can be used to setup
# button states.
# startupCommand = "deadd-notification-center-startup"

# If newFirst is set to true, newest notifications appear on the top
# of the notification center. Else, notifications stack, from top to
# bottom.
newFirst = true

# If useActionIcons is set to true, Action Buttons can show Icon
useActionIcons = true

# If true, the transient field in notifications will be ignored and
# the notification will be persisted in the notification center anyways
ignoreTransient = false

# If true, markup (<u>, <i>, <b>, <a>) will be displayed properly
useMarkup = true

# If true, html entities (&#38; for &, &#37; for %, etc) will be parsed 
# properly. This is useful for chromium-based apps, which tend to send 
# these in notifications. 
parseHtmlEntities = true

# If set to true, the parameter noClosedMsg can be set on
# notifications. If noClosedMsg is set to true on a notification,
# DBUS NotificationClosed messages will not be send for this
# notification.
configSendNotiClosedDbusMessage = false

# If set to true: If no icon is passed by the app_icon parameter 
# and no application "desktop-entry"-hint is present, the notification
# center will try to guess the icon from the application name (if present).
# Default is true.
guessIconFromAppname = true

# See section "Notification based scripting" for an explanation
#match = "title=Abc;body=abc":"app=notify-send"
#modify = "transient=false"
#run = "":"killall notify-send"

[notification-center-notification-popup]

# Default timeout used for notifications in milli-seconds.  This can
# be overwritten with the "-t" option (or "--expire-time") of the
# notify-send command.
notiDefaultTimeout = 10000

# Margin above notifications (in pixels). This can be used to avoid
# overlap between notifications and a bar such as polybar or i3blocks.
distanceTop = 50

# Margin on the right of the notification (in pixels).
distanceRight = 50

# Vertical distance between 2 notifications (in pixels).
distanceBetween = 20

# Width of the notifications.
width = 300

# Monitor on which the notification will be printed.
monitor = 0

# If true, the notifications will open on the screen, on which the
# mouse is
followMouse = false

# The display size of the application icons in the notification 
# pop-ups and in the notification center
iconSize = 20

# The maximal display size of images that are part of notifications
# for notification pop-ups and in the notification center
maxImageSize = 100

# The margin around the top, bottom, left, and right of notification
# images. Applies to popup notifications and in-center notifications.
imageMarginTop = 15
imageMarginBottom = 15
imageMarginLeft = 15
imageMarginRight = 0

# Truncates notification bodies with '...' at the specified number of 
# lines. If -1 is specified, the body text will not be truncated.
# Applies only to popup notifications
shortenBody = 5

# The mouse button for closing a popup. Must be either "mouse1", 
# "mouse2", "mouse3", "mouse4", or "mouse5"
dismissButton = mouse1

# The mouse button for opening a popup with the default action.
# Must be either "mouse1", "mouse2", "mouse3", "mouse4", or "mouse5"
defaultActionButton = mouse3

[buttons]
### This section describes the configurable buttons within the
### notification center and NOT the buttons that appear in the
### notifications

# Note: If you want your buttons in the notification center to be
#       squares you should verify that the following equality holds:
#       [notification-center]::width
#          == [buttons]::buttonsPerRow * [buttons]::buttonHeight
#             + ([buttons]::buttonsPerRow + 1) * [buttons]::buttonMargin

# Numbers of buttons that can be drawn on a row of the notification
# center.
buttonsPerRow = 5

# Height of buttons in the notification center (in pixels).
buttonHeight = 60

# Horizontal and vertical margin between each button in the 
# notification center (in pixels).
buttonMargin = 2

# Labels written on the buttons in the notification center. Labels
# should be written between quotes and separated by a colon. For
# example:
# labels = "VPN":"Bluetooth":"Wifi":"Screensaver"

# Each label is represented as a clickable button in the notification
# center. The commands variable below define the commands that should
# be launched when the user clicks on the associated button.  There
# should be the same number of entries in `commands` and in `labels`
# commands = "sudo vpnToggle":"bluetoothToggle":"wifiToggle":"screensaverToggle"

CSS styling

In the file ${XDG_CONFIG_HOME}/deadd/deadd.css (usually .config/deadd/deadd.css) you can add CSS styles (GTK3-flavor). Should the installation not have created a dead.css, you can use the content of style.css as a foundation.

The following class-names for labels are defined:

  • Notifications:
    label.deadd-noti-center.notification.appname
    Appname
    label.deadd-noti-center.notification.body
    Textbody
    label.deadd-noti-center.notification.title
    Notification title
    image.deadd-noti-center.notification.image
    Image of a notification
    image.deadd-noti-center.notification.icon
    Appicon
  • Notifications in the notification center:
    label.deadd-noti-center.in-center.appname
    Appname
    label.deadd-noti-center.in-center.body
    Textbody
    label.deadd-noti-center.in-center.title
    Notification title
    label.deadd-noti-center.in-center.time
    Notification time
    image.deadd-noti-center.in-center.image
    Image of a notification
    image.deadd-noti-center.in-center.icon
    Appicon
    button.deadd-noti-center.in-center.button-close
    Close button on notification
  • Notification-center:
    label.deadd-noti-center.noti-center.time
    The big time at the top
    label.deadd-noti-center.noti-center.date
    The date text
    label.deadd-noti-center.noti-center.delete-all
    “Delete all” Button

Examples:

image.deadd-noti-center.notification.icon,
label.deadd-noti-center.notification.appname,
image.deadd-noti-center.in-center.icon,
label.deadd-noti-center.in-center.appname {
    opacity: 0
}
.deadd-noti-center {
    font-family: monospace;
}

Notification-based scripting

You can modify notifications if they match certain criteria.

Matching:

The criteria you can specify are equality for the following parameters:

  • title
  • body
  • app
  • time
  • icon

You can test a parameter like this: title=Abc. If you want to test for more than one parameter (for all of them to be true) you can concatenate the criteria with ; like this: title=Abc;body=You can baz yourself.

Modifying:

You can set the following parameters:

  • title
  • body
  • app
  • time
  • timeout (specified in milliseconds)
  • right (overrides distanceRight from the configuration)
  • top (overrides distanceTop from the configuration)
  • icon (overrides the app-icon, value must be either empty, a path to an image or a gtk-icon-name)
  • image (overrides the image of the notification, value must be either empty, a path to an image or a gtk-icon-name)
  • transient (value has to be true or false)
  • noClosedMsg (value has to be true or false, if set to true it will prevent that a DBUS NotificationClosed message will be send for this notification. Only applies if the configuration parameter configSendNotiClosedDbusMessage is set to true)
  • removeActions (value can be anything, if used, no action buttons will be displayed on the notifications)

If you want to set more than one parameter you can concatenate them with ; like this: app=Crashmaster 2000;time=4:20.

Running Commands:

Not implemented, yet.

[notification-center]
match = "title=Abc;body=abc":"app=notify-send"
modify = "transient=false"
run = "":"killall notify-send"

Issues and goals

See here: Log of issues

Contribute

First of all: Contribution is obviously 100% optional.

If you do want to contribute, feel free to send me an email (for the address, see on my profile).

If you do not want to contribute with your time, you can buy me a beer ;). Someone mentioned, she would be willing to donate, so here is my PayPal link: https://paypal.me/phuhl. Should you consider to donate, please be aware that this does not buy you the right to demand anything. This is a hobby. And will be. But if you just want to give me some motivation by showing me that someone appreciates my work, feel free to do so.

See also

Also take a look at my notify-send.py which imitates notify-send (libnotify) but also is able to replace notifications.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap