Commit graph

62 commits

Author SHA1 Message Date
Daniel Eklöf
7639186865
terminfo: install to $datadir/foot/terminfo by default, append to TERMINFO_DIRS
As of 2021-07-31, ncurses ships its own version of foot’s terminfo.

Since:

* It doesn’t have the non-standard Sync,Tc,setrgbf,setrgbb
  capabilities.
* It doesn’t set hs,fsl,dsl (statusbar).
* We want to be able to update our termminfo without waiting for an
  ncurses release.
* Foot should be installable and usable on Linux systems that doesn’t
  have the latest ncurses.

we still want to ship our own version. We can however not install it
to the default terminfo location (e.g. /usr/share/terminfo), since it
will collide with the ncurses provided files.

Our options are to either rename our terminfo to something else, or to
keep the name, but install our terminfo files somewhere else.

The first option would be the easy one. However, I think it makes
sense to use the same name. For example, a user that SSH’s into a
remote system that does *not* have our own version installed,
but *does* have the ncurses one, will gracefully fall back to that
one, which is better than manually having to set
e.g. TERM=xterm-256color.

Now, if we want to use the same name, we need to install it somewhere
else. But where? And how do we ensure our version is preferred over
the ncurses one?

I opted to $datadir/foot/terminfo (e.g. /usr/share/foot/terminfo) by
default. It makes it namespaced to foot (i.e. we’re not introducing a
new “standard” terminfo location), thus guaranteeing it wont collide
with ncurses.

To enable applications to find it, we export TERMINFO_DIRS. This is a
list of *additional* directories to search for terminfo files. If it’s
already defined, we *append* to it.

The nice thing with this is, if there’s no terminfo in that
location (e.g. when you SSH into a remote), the default terminfo
location is *also* searched. But only *after* having searched through
TERMINFO_DIRS.

In short: our version is preferred, but the ncurses one (or an older
version of our terminfo package!) will be used if ours cannot be
found.

To enable packagers full control over the new behavior, the existing
meson command line options have been modified, and a new option added:

-Dterminfo=disabled|enabled|auto: *build* and *install* the terminfo
files.

-Dcustom-terminfo-install-location=<path>: *where* the terminfo files
are expected to be found.

This *needs* to be set *even* if -Dterminfo=disabled. For example, if
the packaging script builds and packages the terminfo files separate
from the regular foot build. The path is *relative to $prefix*, and
defaults to $datadir/foot/terminfo.

This is the value that will be appended to TERMINFO_DIRS. Note that
you can set it to ‘no’, in which case foot will *not* set/modify
TERMINFO_DIRS. Only do this if you don’t intend to package foot’s
terminfo files at all (i.e. you plan on using the ncurses ones only).

-Ddefault-terminfo=foot. Allows overriding the default TERM
value. This should only be changed if the target platform doesn’t
support terminfo files.

Closes #671
2021-08-17 21:04:30 +02:00
Daniel Eklöf
0b6ec4da71
client: remove info log of client app’s exit-code 2021-07-30 15:38:20 +02:00
Craig Barnes
5dca0458a0 log: add LOG_CLASS_NONE and use as initializer for log_level
This means that logging will be completely disabled until log_init()
has been called, which is useful to prevent log spam when running
UNITTEST{} blocks in debug builds.

Note that this doesn't change the default log level at runtime, which
was already being set to LOG_CLASS_INFO in main.c and client.c.

The new log level is also exposed to the command-line interface as
`--log-level=none`, which allows disabling logging entirely.
2021-06-26 22:15:09 +01:00
Daniel Eklöf
3f0f5ec3b7
client: add +/-graphemes to version output 2021-06-24 17:50:44 +02:00
Daniel Eklöf
15e7e80245
client: make sure ‘fd’ is initialized in all error paths 2021-06-23 15:32:03 +02:00
Daniel Eklöf
5fc8275eb2
client: add and use function push_override()
We now track override data (length + malloc:ed string) in a struct,
and push this struct to our overrides linked list.

There’s a new function, push_override() that takes a string,
calculates its length, strdup() it and pushes it to the linked
list. This function also length-checks the string, to ensure we don’t
overflow.

This way, we don’t have to loop the overrides list twice; once when
calculating the total length of all overrides, and once when sending
the overrides to the server.

Now, we can update the total length as we add overrides (i.e while
parsing the command line, instead of afterwards).

This means we only have to loop the list once, and that’s when sending
it. This also means there’s no longer any need to malloc an array
holding the lengths of each override.
2021-06-23 15:12:09 +02:00
Daniel Eklöf
63a64bdca1
client: implement -o,--override 2021-06-23 15:12:08 +02:00
Daniel Eklöf
136d60606a
client: send overrides for everything that is publicly visible in the conf
Send a generic “overrides” list to the server, containing options in
text, on the format “section.key=value”.

This reduces the size of the base client/server protocol packet, as
well as opens up for a generic -o,--override command line option (not
yet implemented).
2021-06-23 15:12:08 +02:00
Daniel Eklöf
da923100ca
main/client: change exit code
* foot exits with -26/230
* footclient exits with -36/220

This is to give each application a range of exit codes. Currently
unused, but we may want to change this in the future.
2021-05-04 10:41:22 +02:00
Daniel Eklöf
a1b41bd186
foot/footclient: use a custom exit code when foot/footclient fail to run
Normally, foot and footclient uses the exit code from the client
application (i.e. the shell).

However, foot (or footclient) itself may fail to run; if run outside
of a Wayland session, or no fonts are installed, or the client
application/shell cannot be found (“foot lsdjfldsjf”) etc.

Up until now, there has been no way to differentiate these kind of
failures from the client application exiting with code 1.

This patch changes foot’s failure exit code to -27/229, and
footclient’s to -28/228. Note that footclient will exit with foot’s
-27/229 if footclient ran successfully, but the foot server failed to
instantiate a new window.

Closes #466.
2021-05-04 10:40:38 +02:00
Daniel Eklöf
9b20764f35
features: --version now logs +/-pgo
That is, whether the binary was compiled with PGO or not.
2021-03-26 20:30:13 +01:00
Felipe Trzaskowski
3ed9314266 add option to detach the client process from the terminal instance 2021-03-13 05:48:55 -03:00
Daniel Eklöf
464851fac1
client: repair usage output 2021-03-12 21:53:11 +01:00
Daniel Eklöf
84f840a197
client: remove excess ‘-’ from ‘--log-level’ in usage 2021-03-12 21:51:07 +01:00
Daniel Eklöf
5b0ebee290
client: -D,--working-directory: check path exists and is a directory 2021-02-13 10:48:58 +01:00
Daniel Eklöf
19868c9c8d
main/client: add -D,--working-directory=DIR
This overrides the CWD the slave process chdir()’s into before
exec:ing the client application.
2021-02-12 21:42:53 +01:00
Daniel Eklöf
59b127dc69
main/client: add missing short options to usage (--help output)
Initially, these options *did not* have short options. Then, in
e813883367, the short options were added
to footclient’s getopt_long() call.

This was in a sense incorrect. But instead of reverting it, the short
options were made official in
8eaa195990, by adding the short options
to foot, documenting them in the man pages, and adding them to the
shell completions.

Though the commit message of 8eaa195990
says the options have now been included in usage(), they were in
fact *not* added to usage.

This patch does just that.
2021-02-12 09:02:25 +01:00
Craig Barnes
5437321f97 main: client: factor out some common code for "--log-level" option 2021-02-11 11:08:18 +00:00
Daniel Eklöf
4d42094a64
client: add -d,--log-level 2021-02-09 21:22:16 +01:00
Daniel Eklöf
0bb928e02f
client: explicitly use a 64-bit type for ‘total_len’
This fixes an out-of-range comparison in 32-bit builds:

 client.c:289:19: error: result of comparison of constant 4294967296 with expression of type 'size_t' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
        if (total_len >= 1llu << (8 * sizeof(uint32_t)) ||
            ~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2021-01-23 09:52:42 +01:00
Jan Beich
567a8de3b0
client/server: switch to POSIX header for sockaddr_un
client.c:13:10: fatal error: 'linux/un.h' file not found
 #include <linux/un.h>
          ^~~~~~~~~~~~
client.c:195:24: error: variable has incomplete type 'struct sockaddr_un'
    struct sockaddr_un addr = {.sun_family = AF_UNIX};
                       ^
client.c:195:12: note: forward declaration of 'struct sockaddr_un'
    struct sockaddr_un addr = {.sun_family = AF_UNIX};
           ^
server.c:11:10: fatal error: 'linux/un.h' file not found
 #include <linux/un.h>
          ^~~~~~~~~~~~
server.c:307:24: error: variable has incomplete type 'struct sockaddr_un'
    struct sockaddr_un addr;
                       ^
server.c:307:12: note: forward declaration of 'struct sockaddr_un'
    struct sockaddr_un addr;
           ^
server.c:347:24: error: variable has incomplete type 'struct sockaddr_un'
    struct sockaddr_un addr = {.sun_family = AF_UNIX};
                       ^
server.c:347:12: note: forward declaration of 'struct sockaddr_un'
    struct sockaddr_un addr = {.sun_family = AF_UNIX};
           ^
server.c:394:24: error: variable has incomplete type 'struct sockaddr_un'
    struct sockaddr_un addr = {.sun_family = AF_UNIX};
                       ^
server.c:394:12: note: forward declaration of 'struct sockaddr_un'
    struct sockaddr_un addr = {.sun_family = AF_UNIX};
           ^
2021-01-21 12:00:02 +01:00
Craig Barnes
e56136ce11 debug: rename assert() to xassert(), to avoid clashing with <assert.h> 2021-01-16 20:16:00 +00:00
Craig Barnes
22f25a9e4f Print stack trace on assert() failure or when calling fatal_error()
Note: this uses the __sanitizer_print_stack_trace() function from the
AddressSanitizer runtime, so it only works when AddressSanitizer is
in use.
2021-01-16 19:56:33 +00:00
Daniel Eklöf
77bc7c8b2c
features: include compile-time enable/disable state of features when printing version 2020-12-07 20:44:11 +01:00
Craig Barnes
b8fc2e19da client: add new "--window-size-*" options to docs and CHANGELOG.md 2020-11-22 18:52:51 +00:00
Craig Barnes
748f98e0c0 client: add "--window-size-pixels" and "--window-size-chars" options 2020-11-22 18:52:28 +00:00
Craig Barnes
82caa7bd04 client: fix handling of "-m" command-line flag 2020-11-22 16:40:15 +00:00
Craig Barnes
e813883367 client: add missing options to getopt_long(3) optstring argument 2020-11-21 20:34:49 +00:00
Daniel Eklöf
997c6a4ae3
client: we added argv lengths twice 2020-11-21 20:46:08 +01:00
Daniel Eklöf
0b3a84bd9c
client: avoid doing a signed vs. unsigned comparison 2020-11-21 20:29:47 +01:00
Daniel Eklöf
fc81f413c0
client/server: simplify setup packet handling
Instead of writing (and logging errors for) every parameter, one at a
time, send all fixed size data in a single struct, followed by all the
variable length data.
2020-11-21 20:21:18 +01:00
Daniel Eklöf
c9de30e2bc
client: let getopt_long(3) print error messages
Closes #191
2020-11-10 19:04:20 +01:00
Craig Barnes
7a77958ba2 Convert most dynamic allocations to use functions from xmalloc.h 2020-08-08 20:37:57 +01:00
Daniel Eklöf
5e26d3ef47
server/client: use $WAYLAND_DISPLAY instead of $XDG_SESSION_ID in default socket path
Foot is a Wayland client and cannot be run outside of a Wayland
session. As such, it makes more sense to use $WAYLAND_SESSION instead
of $XDG_SESSION_ID in the default socket path since this makes it
clearer which Wayland session we belong to.

Closes #55.
2020-08-02 13:10:31 +02:00
Daniel Eklöf
f3c301ee8b
doc: foot.1: fix default path in -s,--server
The documentation incorrectly stated that the default path is
$XDG_RUNTIME_DIR/foot.sock.

The correct default path is

* $XDG_RUNTIME_DIR/foot-$XDG_SESSION_ID.sock
* $XDG_RUNTIME_DIR/foot-no-session.sock
* /tmp/foot.sock

Depending on whether XDG_RUNTIME_DIR and XDG_SESSION_ID has been set
or not.

This also removes the '<>' from the default when XDG_SESSION_ID is not
set.

Closes #53.
2020-08-02 12:32:10 +02:00
Daniel Eklöf
3943cad7ed
client/server: implement '--hold' in footclient 2020-05-26 20:11:38 +02:00
Daniel Eklöf
5b70f94827
main/client: be POSIXLY_CORRECT when parsing command line
This means command line parsing stops when it encounters the first
nonoption argument.

The result is that one no longer need to use '--' to ensure arguments
are passed to the shell/command, instead of parsed by foot.

That is, instead of

  foot -- sh -c true

one can now do

  foot sh -c true

Arguments to foot *must* go before the command:

  foot --fullscreen sh -c true
2020-05-08 18:43:03 +02:00
Daniel Eklöf
ec7a768487
conf: add 'title' conf option and --title command line option 2020-04-01 19:59:47 +02:00
Daniel Eklöf
4d52a870b4
conf: add app-id config option and --app-id command line option 2020-04-01 18:40:51 +02:00
Daniel Eklöf
758fd9fd58
client: add --maximized and --fullscreen
We now create a copy of the config for each client, and updates it
with the values passed from the client.

Since we're not actually cloning it (and e.g. strdup() all strings
etc) we can't call conf_destroy() to free it, but need to free just
the strings we've replaced.
2020-03-27 21:14:49 +01:00
Daniel Eklöf
9049488acc
client: log path we actually tried to connect to (and failed) 2020-03-10 18:06:10 +01:00
Daniel Eklöf
1c42fadcf7
client: update --server-socket usage to mention XDG_SESSION_ID 2020-03-10 18:06:10 +01:00
Daniel Eklöf
25792a7e8c
server/client: add XDG_SESSION_ID to the default socket path
This allows multiple foot servers to run in multiple sessions.
2020-03-09 18:47:10 +01:00
Daniel Eklöf
54fbfb6405
client: make sure 'cwd' is in scope of all goto's 2020-02-20 20:21:34 +01:00
Daniel Eklöf
e751227dc6
client: allocate current working directory buffer dynamically 2020-02-20 18:45:42 +01:00
Daniel Eklöf
b5efe984bb
slave: prefix argv[0] with a '-' when spawning a login-shell 2020-02-20 18:36:09 +01:00
Daniel Eklöf
8dee9bf942
client: add --login-shell command line option 2020-02-20 18:34:51 +01:00
Daniel Eklöf
82b8853f17
main: add --print-pid=FILE|FD
When specified, our PID is written to the specified file (or FD),
after we've successfully started up.
2020-02-05 19:54:16 +01:00
Daniel Eklöf
277735db65
client/server: client sends its CWD to server 2019-12-21 19:56:37 +01:00
Daniel Eklöf
a0fcec3a3d
log: caller can control syslog level 2019-12-17 19:07:28 +01:00