{"id":15657730,"url":"https://github.com/nobodyxu/swaystatus","last_synced_at":"2025-09-11T01:07:55.819Z","repository":{"id":49547263,"uuid":"337929801","full_name":"NobodyXu/swaystatus","owner":"NobodyXu","description":"A minimal executable for displaying sway status per second","archived":false,"fork":false,"pushed_at":"2024-03-08T23:59:56.000Z","size":641,"stargazers_count":26,"open_issues_count":3,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-28T09:34:48.396Z","etag":null,"topics":["backlight","battery","brightness","sensors-reading","status-bar","swaybar","swaywm","volume"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NobodyXu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-11T04:34:03.000Z","updated_at":"2025-04-06T11:58:27.000Z","dependencies_parsed_at":"2024-03-09T00:35:03.891Z","dependency_job_id":"6daf8bcd-9aba-4158-9283-831ae4c61142","html_url":"https://github.com/NobodyXu/swaystatus","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"purl":"pkg:github/NobodyXu/swaystatus","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NobodyXu%2Fswaystatus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NobodyXu%2Fswaystatus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NobodyXu%2Fswaystatus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NobodyXu%2Fswaystatus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NobodyXu","download_url":"https://codeload.github.com/NobodyXu/swaystatus/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NobodyXu%2Fswaystatus/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274557583,"owners_count":25307516,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-10T02:00:12.551Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backlight","battery","brightness","sensors-reading","status-bar","swaybar","swaywm","volume"],"created_at":"2024-10-03T13:09:25.467Z","updated_at":"2025-09-11T01:07:55.799Z","avatar_url":"https://github.com/NobodyXu.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# swaystatus\n\nA lightweight yet feature-rich status bar for i3bar or swaybar.\n\n![screenshot]\n\nIt is written completely in C/C++ to make it as lightweight as possible and specifically, to avoid creating new processes every second as in bash script.\n\nIt uses libraries like `libasound` and glibc function `getifaddrs` to retrieve volume information as opposed to using `amixer` and `ip addr`.\n\nFor battery, backlight, load, and meminfo, it reads directly from `/sys/class/power_supply`,\n`/sys/class/backlight`, `/proc/loadavg` and `/proc/meminfo`.\n\n## Runtime Dependency\n - `libasound.so.2`\n - `libjson-c.so.5` (also used by sway and swaybar)\n - `libsensors.so.5`\n\n## Build\n\nInstall `clang` (must have lto support), `lld`, `make` and `pkg-config`, then run\n\n```\ngit clone --recurse-submodules https://github.com/NobodyXu/swaystatus\ncd swaystatus/src\nmake -j $(nproc)\n```\n\nYou can customize ou build via environment variable:\n - `BUILD_DIR`: affects where the built object will be put. Default is `.`.\n - `TARGET_DIR`: where the executable will be installed when `make install` is executed. Default is `/usr/local/bin`\n - `PYTHON`: whether to include embeded python interpreter support in `swaystatus`, can be `true` or `false`. Default is `true`.\n - `DEBUG`: whether to have a debug build or release build. `true` for debug build and `false`for release build. Default is `false`.\n - `EXCEPTION`: whether to enable C++ exception. `false` to disable C++ exception.\n\nTo install, run `sudo make install`, which by default will install a single binary `swaystatus` to `/usr/local/bin`.\n\n## Usage\n\n### swaybar usage:\n\n```\nswaystatus: Usage: swaystatus [options] configuration_filename\n\n  --help                    Show help message and exit\n  --interval=unsigned_msec  Specify update interval in milliseconds, must be an unsigner integer.\n                            By default, the interval is set to 1000 ms.\n```\n\nTo reload `swaystatus`, send `SIGUSR1` to `swaystatus` process.\n\n### Config file format\n\n    {\n        \"order\": [\"network_interface\", \"time\"],\n        \"_comment\": \"element order specify the order of which blocks will appear.\",\n        \"_comment2\": \"If a block is not specified in order, it will not appear.\",\n\n        \"name\": {\n            \"format\": \"Hello, {variable_name}\",\n            \"short_format\": \"hello\", \n            \"update_interval\": 20,\n            \"color\": \"##RRGGBBA\",\n            \"background: \"##RRGGBBA\",\n            \"border\": \"##RRGGBBA\",\n            \"border_top\": 1,\n            \"border_bottom\": 1,\n            \"border_left\": 1,\n            \"border_right\": 1,\n            \"min_width\": 1,\n            \"align\": \"center\",\n            \"separator\": true,\n            \"separator_block_width\": 9,\n            \"markup\": \"none\",\n\n            \"click_event_handler\": {\n                \"type\": \"python\",\n                \"module_name\": \"hello\",\n                \"function_name\": \"handler\"\n            }\n        },\n        \"_comment\": \"Any variable starts with '_' is a comment\"\n    }\n\nAll property present for \"name\" above are optional.\n\u003cbr\u003eFor volume, you can also set property \"mix_name\" and \"card\".\n\nThe following values are valid name:\n\n - brightness\n - volume\n - battery\n\n   The configuration block of battery support `excluded_model` to exclude certain battery devices\n   from the output of `swaystatus`.\n - network_interface\n - load\n - memory_usage\n - time\n - sensors\n\n**Any unrecognized parameters will be ignored.**\n\n#### \"format\"\n\nIt is used internally to generate the \"full_text\" that will be passed to swaybar.\n\nFormatting for blocks other than time is done using [fmt - Format String Syntax].\n\u003cbr\u003eFormatting for block time is parsed by [`strftime`].\n\nIn the format string, user is capable of taking advantage of \n[format variables](/#Format_Variables) to customize the output.\n\n#### \"short_format\"\n\nIt is used to generate \"short_text\", which is used by `swaybar` when it decided that the \n\"full_text\" is too long.\n\n#### Click Event Handling Support\n\nTO enable click event handling for a block, add json object \"click_event_handler\" \nto the block that block.\n\nThe return value of it can be `or`ed from the following values:\n - `0` do nothing\n - `1` force the module to update\n - `2` force the module to reload\n\nCurrently, the handler can be written in python or C/C++.\n\n##### Loading python handler\n\nFor loading python handler, add `\"type\": \"python\"` to your \"click_event_handler\", then specify \nthe \"module_name\" and \"function_name\" of the handler.\n\n`swaystatus` will attempt to load the module from the same directory of your configuration file, \nyour current working dir, any path you specified with environment variable `PYTHONPATH` and your \nsystem module paths.\n\nIf instead you want to embed the python code into your configuration file, add \"code\" to your \n\"click_event_handler\" and assign your code as value to it.\n\nThe python function is expected to have signature (Check [here](https://www.mankier.com/7/swaybar-protocol#Click_Events) for more information):\n\n```\n(instance: str, click_pos: Tuple[int, int], button: int, event: int, relative_click_pos: Tuple[int, int], blocksize: Tuple[int, int]) -\u003e int\n```\n\nYour function is expected to return 0 and any exception thrown in your function must be handled, \notherwise `swaystatus` will print that error and exit.\n\n##### Loading C/C++ handler\n\nYou C/C++ code has to be compiled with `-fPIC -shared`.\n\nFor loading python handler, add `\"type\": \"dynlib\"` to your \"click_event_handler\", then specify \nthe \"module_name\" and \"function_name\" of the handler.\n\nJust like loading python, `swaystatus` will attemp to load the shared library from the same \ndirectory of your configuration file, your current working dir.\n\nIt is loaded using `dlopen`, so `LD_LIBRARY_PATH`, `/etc/ld.so.cache`, `/lib` and `/usr/lib` is \nalso searched.\n\nYou can also specify the path instead of a name directly in the `module_name`, which is perfectly \nvalid.\n\nThe C/C++ function is expected to be `export`ed in `\"C\"` and have signature:\n\n```c\n#include \u003cstdint.h\u003e\n\nstruct Pos {\n    uint64_t x;\n    uint64_t y;\n};\ntypedef struct Pos ClickPos;\ntypedef struct Pos BlockSize;\n\nint f(\n    const char *instance, \n    const ClickPos *pos,\n    uint64_t button,\n    uint64_t event,\n    const ClickPos *relative_pos,\n    const BlockSize *size\n)\n```\n\nYour function is expected to return 0.\n\n#### Disable block\n\nIf you want to disable a certain feature, say brightness,\nthen add the following to your configuration:\n\n    {\n        \"brightness\": false,\n    }\n\nOr if you are using element \"order\" for specifing block order, then you can simply\nremove the name from \"order\".\n\nNote that `{\"brightness\": false}` overrides \"order\":\n\u003cbr\u003eIf block specified in \"order\" is disabled by setting it to `false`, then the block\nwill not appear.\n\n#### `custom`\n\nUsing this block, you can import a python/c module and display whatever you want in this \nblock.\n\nYou need to provide `update_callback` and `do_print_callback`, which need to have the \nsame fields as click event handler `type`, `module_name`, `function_name`,\n(optional `code` for python).\n\nCheck [`example-config.json`](/example-config.json) for example configuration of this \nblock.\n\n#### `update_interval`\n\nIf specified, then the block will update at `update_interval * main_loop_interval ms`,\nwhere `main_loop_interval` is the value passed by cmdline arg `--interval=` or `1000 ms`\nby default.\n\n##### `update_interval` for `sensors`\n\nThe sensors on computer are so many that they cannot be fitted into one line, so `swaystatus`\ninstead, print one sensor each time and once `update_interval` is reached, next sensor is shown\nat the `swaybar`.\n\nWhen all sensors are shown, `swaystatus` will then update the sensors reading from the computer.\n\n### Format_Variables\n\n#### Battery format variables:\n\n - `has_battery`: check whether battery device exists\n - `per_battery_fmt_str`, which is used to print every battery on this system.\n   \n   It contains the following variables:\n    - `name`\n    - `present`\n    - `technology`\n    - `model_name`\n    - `manufacturer`\n    - `serial_number`\n    - `status`\n    - `cycle_count`\n    - `voltage_min_design`\n    - `voltage_now`\n    - `charge_full_design`\n    - `charge_full`\n    - `charge_now`\n    - `capacity`\n    - `capacity_level`\n    - `is_charging`        (Check section \"Conditional Variable\" for usage)\n    - `is_discharging`\n    - `is_not_charging`\n    - `is_full`\n\n#### Memory Usage variables:\n\n - `MemTotal`\n - `MemFree`\n - `MemAvailable`\n - `Buffers`\n - `Cached`\n - `SwapCached`\n - `Active`\n - `Inactive`\n - `Mlocked`\n - `SwapTotal`\n - `SwapFree`\n - `Dirty`\n - `Writeback`\n - `AnonPages`\n - `Mapped`\n - `Shmem`\n\nThe unit (supports 'BKMGTPEZY') of the variables printed can be specified.\n\u003cbr\u003eFor example, '{MemTotal:K}' will print MemTotal in KiloBytes.\n\n#### Volume variables:\n\n - `volume`\n\n#### Load variables:\n\n - `loadavg_1m`\n - `loadavg_5m`\n - `loadavg_15m`\n - `running_kthreads_cnt`\n - `total_kthreads_cnt`\n - `last_created_process_pid`\n\n#### Brightness variables:\n\nNOTE that these variables are evaluated per backlight_device.\n\n - `backlight_device`\n - `brightness`\n - `max_brightness`\n - `has_multiple_backlight_devices` (this is a Conditional Variable)\n\n#### Network Interface variables;\n\n - `is_connected`\n - `is_not_connected`\n - `per_interface_fmt_str`:\n    The specification for this variable will be formatted once for each interface.\n\n    It contains subvariables that can be used inside:\n     - `HAS_UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO`\n     - `has_broadcast_support`\n     - `is_pointopoint`\n     - `has_no_arp_support`\n     - `is_in_promisc_mode`\n     - `is_in_notrailers_mode`\n     - `is_master`\n     - `is_slave`\n     - `has_multicast_support`\n     - `has_portsel_support`\n     - `is_automedia_active`\n     - `is_dhcp`\n\t - `rx_packets`\n\t - `tx_packets`\n\t - `rx_bytes` (Supports unit specification, checks [Memry Usage Variables](#memory-usage-variables) for more info)\n\t - `tx_bytes` (Supports unit specification, checks [Memry Usage Variables](#memory-usage-variables) for more info)\n\t - `rx_errors`\n\t - `tx_errors`\n\t - `rx_dropped`\n\t - `tx_dropped`\n\t - `multicast`\n\t - `collisions`\n\t - `rx_length_errors`\n\t - `rx_over_errors`\n\t - `rx_crc_errors`\n\t - `rx_frame_errors`\n\t - `rx_fifo_errors`\n\t - `rx_missed_errors`\n\t - `tx_aborted_errors`\n\t - `tx_carrier_errors`\n\t - `tx_fifo_errors`\n\t - `tx_heartbeat_errors`\n\t - `tx_window_errors`\n\t - `rx_compressed`\n\t - `tx_compressed`\n     - `ipv4_addrs`\n     - `ipv6_addrs`\n\n    Limit of number of ip address can be done via `{ipv4_addrs:1}` and `{ipv6_addrs:1}`\n\n    Optionally if `HAS_UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO`, \n    the following variables are also defined:\n     - `is_lower_up`\n     - `is_dormant`\n     - `is_echo_device`\n\nTo limit number of ip addresses in output, please use `{ipv4_config:1}`.\n\n#### Sensors variables;\n\n - `prefix`: the name of the device\n - `path`: the path to the device in `/sys`\n - `addr`: the internal address of the device in `libsensors`\n - `bus_type`: the type of device\n - `bus_nr`: unclear\n - `reading_number`: the internal index for the specific sensor reading\n - `reading_temp`: the temperature reading from the sensor\n\n#### Format string for time:\n\n#### Conditional Variables\n\nConditional variables are used to conditionally evaulate part of the format string.\n\nFor example, setting \"format\" in \"battery\" to \"{is_charging:Charging}\" will print \"Charging\" only\nwhen the battery is charging.\n\nAll variables start with \"is\" and \"has\" are conditional variables.\n\n#### Recursive Conditional Variable:\n\nIn additional to printing strings conditionally, conditional variables can also be used to\nprint other variables conditionally.\n\nFor example, \"{is_charging:{level}%}\" will print \"98%\" when charging, where\n\"98\" is the actual level of battery.\n\nCheck [`example-config.json`] for the example configuration.\n\n### Use `swaybar` in `sway`\n\n```\nbar {\n    status_command swaystatus\n}\n```\n\n[screenshot]: https://raw.githubusercontent.com/NobodyXu/swaystatus/main/screenshot.png\n[`strftime`]: https://man7.org/linux/man-pages/man3/strftime.3.html\n[fmt - Format String Syntax]: https://fmt.dev/latest/syntax.html\n[`example-config.json`]: https://github.com/NobodyXu/swaystatus/blob/main/example-config.json\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnobodyxu%2Fswaystatus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnobodyxu%2Fswaystatus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnobodyxu%2Fswaystatus/lists"}