Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GPS module #3628

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions include/modules/gps.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once

#include <fmt/format.h>
#include <sys/statvfs.h>

#ifdef WANT_RFKILL
#include "util/rfkill.hpp"
#endif

#include <gps.h>

#include "ALabel.hpp"
#include "util/sleeper_thread.hpp"

namespace waybar::modules {

class Gps : public ALabel {
public:
Gps(const std::string&, const Json::Value&);
virtual ~Gps();
auto update() -> void override;

private:
#ifdef WANT_RFKILL
util::Rfkill rfkill_;
#endif
const std::string getFixModeName() const;
const std::string getFixModeString() const;

const std::string getFixStatusString() const;

util::SleeperThread thread_, gps_thread_;
gps_data_t gps_data_;
std::string state_;

bool hideDisconnected = true;
bool hideNoFix = false;
};

} // namespace waybar::modules
111 changes: 111 additions & 0 deletions man/waybar-gps.5.scd
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
waybar-gps(5) "waybar-gps" "User Manual"

# NAME

waybar - gps module

# DESCRIPTION

*gps* module for gpsd.


# FILES

$XDG_CONFIG_HOME/waybar/config ++
Per user configuration file

# ADDITIONAL FILES

libgps lives in:

. /usr/lib/libgps.so or /usr/lib64/libgps.so
. /usr/lib/pkgconfig/libgps.pc or /usr/lib64/pkgconfig/libgps.pc
. /usr/include/gps

# CONFIGURATION

*format*: ++
typeof: string ++
default: {glyph} ++
The text format.

*tooltip*: ++
typeof: bool ++
default: true ++
Option to disable tooltip on hover.

*tooltip-format*: ++
typeof: string ++
default: Games running: {glyph} ++
The text format of the tooltip.

*interval*: ++
typeof: integer ++
default: 5 ++
The interval in which the GPS information gets polled (e.g. current speed).
Significant updates (e.g. the current fix mode) are updated immediately.

*hide-disconnected*: ++
typeof: bool ++
default: true ++
Defines if the module should be hidden if there is no GPS receiver.

*hide-no-fix*: ++
typeof: bool ++
default: false ++
Defines if the module should be hidden if there is no GPS fix.

# FORMAT REPLACEMENTS

*{mode}*: Fix mode

*{status}*: Technology used for GPS fix. Not all GPS receivers report this.

*{latitude}*: Latitude, decimal degrees. Can be NaN.

*{latitude_error}*: Latitude uncertainty, meters. Can be NaN.

*{longitude}*: Longitude, decimal degrees. Can be NaN.

*{longitude_error}*: Longitude uncertainty, meters. Can be NaN.

*{altitude_hae}*: Altitude, height above ellipsoid, meters. Can be NaN.

*{altitude_msl}*: Longitude, MSL, meters. Can be NaN.

*{altitude_error}*: Altitude uncertainty, meters. Can be NaN.

*{speed}*: Speed over ground, meters/sec. Can be NaN.

*{speed_error}*: Speed uncertainty, meters/sec. Can be NaN.

*{climb}*: Vertical speed, meters/sec. Can be NaN.

*{climb_error}*: Vertical speed uncertainty, meters/sec. Can be NaN.

*{satellites_visible}*: Number of satellites visible from the GPS receiver.

*{satellites_used}*: Number of satellites used for the GPS fix.

# EXAMPLES

```
"gps": {
"format": "{mode}",
"format-disabled": "", // an empty format will hide the module
"format-no-fix": "No fix",
"format-fix-3d": "{status}",
"tooltip-format": "{mode}",
"tooltip-format-no-fix": "{satellites_visible} satellites visible",
"tooltip-format-fix-2d": "{satellites_used}/{satellites_visible} satellites used",
"tooltip-format-fix-3d": "Altitude: {altitude_hae}m",
"hide-disconnected": false
}
```
# STYLE

- *#gps*
- *#gps.disabled* Applied when GPS is disabled.
- *#gps.fix-none* Applied when GPS is present, but there is no fix.
- *#gps.fix-2d* Applied when there is a 2D fix.
- *#gps.fix-3d* Applied when there is a 3D fix.
10 changes: 9 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ libmpdclient = dependency('libmpdclient', required: get_option('mpd'))
xkbregistry = dependency('xkbregistry')
libjack = dependency('jack', required: get_option('jack'))
libwireplumber = dependency('wireplumber-0.5', required: get_option('wireplumber'))
libgps = dependency('libgps', required: get_option('gps'))

libsndio = compiler.find_library('sndio', required: get_option('sndio'))
if libsndio.found()
Expand Down Expand Up @@ -493,6 +494,12 @@ if cava.found()
man_files += files('man/waybar-cava.5.scd')
endif

if libgps.found()
add_project_arguments('-DHAVE_LIBGPS', language: 'cpp')
src_files += files('src/modules/gps.cpp')
man_files += files('man/waybar-gps.5.scd')
endif

subdir('protocol')

app_resources = []
Expand Down Expand Up @@ -531,7 +538,8 @@ executable(
libsndio,
tz_dep,
xkbregistry,
cava
cava,
libgps
],
include_directories: inc_dirs,
install: true,
Expand Down
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ option('jack', type: 'feature', value: 'auto', description: 'Enable support for
option('wireplumber', type: 'feature', value: 'auto', description: 'Enable support for WirePlumber')
option('cava', type: 'feature', value: 'auto', description: 'Enable support for Cava')
option('niri', type: 'boolean', description: 'Enable support for niri')
option('gps', type: 'feature', value: 'auto', description: 'Enable support for gps')
8 changes: 8 additions & 0 deletions src/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
#ifdef HAVE_SYSTEMD_MONITOR
#include "modules/systemd_failed_units.hpp"
#endif
#ifdef HAVE_LIBGPS
#include "modules/gps.hpp"
#endif
#include "modules/cffi.hpp"
#include "modules/custom.hpp"
#include "modules/image.hpp"
Expand Down Expand Up @@ -331,6 +334,11 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name,
if (ref == "systemd-failed-units") {
return new waybar::modules::SystemdFailedUnits(id, config_[name]);
}
#endif
#ifdef HAVE_LIBGPS
if (ref == "gps") {
return new waybar::modules::Gps(id, config_[name]);
}
#endif
if (ref == "temperature") {
return new waybar::modules::Temperature(id, config_[name]);
Expand Down
Loading