Skip to content

Commit 7728495

Browse files
authored
Improve install permissions (#91)
* Improve install command * Update README * Add go+x permissions to C++ program * Specify group permissions for comfortable-swipe-buffer * Bump to version 1.2.4
1 parent 9d25f1c commit 7728495

File tree

5 files changed

+32
-12
lines changed

5 files changed

+32
-12
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.2.3
1+
v1.2.4

comfortable-swipe

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ function start {
115115
debug | buffer $@
116116
else
117117
# detach buffered output
118-
nohup "$BASENAME" debug </dev/null 2>&1 | "$BASENAME" buffer $@ >/dev/null 2>&1 &
118+
nohup "$BASENAME" debug </dev/null 2>&1 | "$BASENAME" buffer $@ >/dev/null 2>&1 & disown
119119
echo "Comfortable swipe is RUNNING in the background"
120120
fi
121121
}

comfortable-swipe-gesture-swipe-xdokey.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void gesture_swipe_xdokey::update() {
134134
gesture_swipe::update();
135135
// scale threshold to 1/10 when gesture is fresh
136136
// acts like our static friction coefficient
137-
float scale = get_previous_gesture() == FRESH ? 0.01f : 1.0f;
137+
const float scale = get_previous_gesture() == FRESH ? 0.01f : 1.0f;
138138
// we are working with floating points which are not exact
139139
// make sure we compare with a very small value (1e-6f)
140140
// if distance goes out of threshold, perform our swipe

comfortable-swipe-main.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,22 @@ int main(int argc, char *argv[]) {
112112
// get input values
113113
string mouse3 = config.count("mouse3") ? config["mouse3"] : config["hold3"];
114114
string mouse4 = config.count("mouse4") ? config["mouse4"] : config["hold4"];
115+
bool nomouse = mouse3.empty() || mouse4.empty(); // TODO: check if mouse invalid
115116
// create our mouse gesture holder
116117
gesture_swipe_xdomouse mousehold(mouse3.data(), mouse4.data());
117118
// start reading lines from input one by one
118119
for (string line; getline(cin, line);) {
119-
// optimization: if no mouse config is set, just run keyboard
120-
if (mousehold.is_swiping() && mousehold.button == MOUSE_NONE) {
120+
if (nomouse) {
121121
keyswipe.run(line.data());
122-
} else if (mousehold.run(line.data())) {
123-
// only allow keyswipe gestures on mouse move
124-
if (mousehold.button == MOUSE_NONE || mousehold.button == MOUSE_MOVE) {
122+
} else {
123+
// optimization: if no mouse config is set, just run keyboard
124+
if (mousehold.is_swiping() && mousehold.button == MOUSE_NONE) {
125125
keyswipe.run(line.data());
126+
} else if (mousehold.run(line.data())) {
127+
// only allow keyswipe gestures on mouse move
128+
if (mousehold.button == MOUSE_NONE || mousehold.button == MOUSE_MOVE) {
129+
keyswipe.run(line.data());
130+
}
126131
}
127132
}
128133
}

install

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,15 @@ function install_configuration_file {
9898
function install_main_program {
9999
# copy source to target with executable permissions
100100
# install to target, with hardcoded version
101-
trysudo sed -E "s/^VERSION=.*/VERSION=$VERSION/" "$SOURCE" > "$TARGET"
102-
# allow execute permissions
101+
if [[ -f "$TARGET" ]]; then
102+
trysudo rm "$TARGET"
103+
fi
104+
trysudo cp "$SOURCE" "$TARGET"
105+
trysudo sed -E "s/^VERSION=.*/VERSION=$VERSION/" -i "$TARGET"
106+
# allow execute permissions with group
103107
trysudo chmod +x "$TARGET"
108+
# make sure non-root user is owner
109+
trysudo chown "$USER" "$TARGET"
104110
echo "Installed: $TARGET"
105111
}
106112

@@ -114,9 +120,17 @@ function install_cpp_program {
114120
# compile program to temporary file first
115121
TMP_TARGET="$(mktemp)"
116122
$COMPILE "$COMPILE_SOURCE" -o "$TMP_TARGET" -DCOMFORTABLE_SWIPE_VERSION="\"$VERSION\"" -DCOMFORTABLE_SWIPE_CONFIG="\"$CONF_TARGET\"" -DCOMFORTABLE_SWIPE_AUTOSTART="\"$AUTOSTART_TARGET\""
117-
# compilation ok, now try to install
118-
# check permissions maybe if will need sudo
123+
# compilation ok, now try to install with sudo
124+
trysudo mkdir -p "$(dirname "$COMPILE_TARGET")"
125+
# remove existing file for permissions to work
126+
if [[ -f "$COMPILE_TARGET" ]]; then
127+
sudo rm "$COMPILE_TARGET"
128+
fi
119129
trysudo mv "$TMP_TARGET" "$COMPILE_TARGET"
130+
# bugfix: add with group permissions
131+
trysudo chmod go+x "$COMPILE_TARGET"
132+
# make sure non-root user is owner
133+
trysudo chown "$USER" "$COMPILE_TARGET"
120134
echo "Installed: $COMPILE_TARGET"
121135
}
122136

@@ -127,6 +141,7 @@ function install_cpp_program {
127141
# /home/$USER/.config/autostart/comfortable-swipe.desktop
128142
#
129143
function install_autostart {
144+
mkdir -p "$(dirname "$AUTOSTART_TARGET")"
130145
cat "$AUTOSTART_SOURCE" > "$AUTOSTART_TARGET"
131146
echo "Installed: $AUTOSTART_TARGET"
132147
}

0 commit comments

Comments
 (0)