Skip to content

Commit

Permalink
make default socket path include $DISPLAY
Browse files Browse the repository at this point in the history
for easier Xephyr handling & stuff
  • Loading branch information
ALEX11BR committed Jan 25, 2022
1 parent aec8b0a commit ae89125
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## Usage
Hotkeys are case-insensitive, with this syntax: `modifier1-modifier2-...-key`. For more info on this, check [this link](https://pkg.go.dev/github.com/alex11br/xgbutil@v0.0.0-20211225011412-f2944427ac98/keybind#hdr-Key_sequence_format) of the underlaying library. Note that, for this moment, controling for the lock (Caps Lock) and the mod2 (Num Lock) modifiers isn't allowed.

The app uses by default some config files: `/etc/gxhkrc` and `$XDG_CONFIG_HOME/gxhk/gxhkrc`. Using the `-C` flag, they can be ignored, and with the `-c` flag, new ones can be specified. Using the `-s` flag, a different socket besides the default `/tmp/gxhk.sock` can be specified.
The app uses by default some config files: `/etc/gxhkrc` and `$XDG_CONFIG_HOME/gxhk/gxhkrc`. Using the `-C` flag, they can be ignored, and with the `-c` flag, new ones can be specified. Using the `-s` flag, a different socket besides the default `/tmp/gxhk$DISPLAY.sock` can be specified.

Here are some examples:
```sh
Expand Down
17 changes: 15 additions & 2 deletions common/args.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package common

import "github.com/alexflint/go-arg"
import (
"fmt"
"os"

"github.com/alexflint/go-arg"
)

type BindCmd struct {
Released bool `arg:"-r" help:"bind the HOTKEY on its release instead of its press"`
Expand All @@ -19,7 +24,7 @@ type InfoCmd struct {
}

type Args struct {
SocketPath string `arg:"-s,--socket" help:"use the given SOCKET file" default:"/tmp/gxhk.sock" json:"-"`
SocketPath string `arg:"-s,--socket" help:"use the given SOCKET file instead of the default one" json:"-"`
ConfigFiles []string `arg:"-c,--config,separate" help:"use the given CONFIG file, besides all the others" json:"-"`
NoDefaultConfigs bool `arg:"-C,--no-default-configs" help:"ignore the default config files" json:"-"`

Expand All @@ -28,8 +33,16 @@ type Args struct {
Info *InfoCmd `arg:"subcommand:info" help:"show infos about the bound keys and their commands" json:",omitempty"`
}

// ParseArgs gives us an Args structure based on the passed command-line flags.
// If its SocketPath is not set, we'll set it for our convenience to the default value,
// which must be computed on the spot using the $DISPLAY environment variable.
// Besides that, the resulting arg.Parser is also returned for our convenience.
func ParseArgs() (Args, *arg.Parser) {
var args Args
p := arg.MustParse(&args)

if args.SocketPath == "" {
args.SocketPath = fmt.Sprintf("/tmp/gxhk%s.sock", os.Getenv("DISPLAY"))
}
return args, p
}
2 changes: 1 addition & 1 deletion gxhk.1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ is a hotkey daemon for X, something like \fBsxhkd\fR. What makes it special is t
Display some help information.
.TP
.BR \-s ", " \-\-socket " " \fIpath
Use \fIpath\fR as the socket path instead of the default \fI/tmp/gxhk.sock\fR.
Use \fIpath\fR as the socket path instead of the default \fI/tmp/gxhk$DISPLAY.sock\fR.

.SS Daemon-start-only options
.TP
Expand Down

0 comments on commit ae89125

Please sign in to comment.