Commit Graph

545 Commits

Author SHA1 Message Date
multiSnow 1377880611 only use int random number for math.randomseed
[This commit was cherry-picked from
https://github.com/awesomeWM/awesome/pull/3124)
2020-08-03 18:04:07 +02:00
Emmanuel Lepage Vallee ee80fe052f init: Add an API level concept to `capi`.
The API level concept is something used by other projects such as
Android and iOS to allow deprecated features to be removed and the
bahavior to be altered without breaking compability with existing
code.

The same will apply to AwesomeWM. The current API level is "4" and
as long as config use this, no deprecation or bahavior change will
be exposed. If the user sets it to an higher value or we release
the next major version and new users start to use the, then current,
default config, they will use the new API level.

The the far future, if ever, we could fork the entire Lua libraries
to support legacy APIs. This would only require to keep the core
API support for those legacy calls. In the meantime, `gears.debug`
will use this to manage the deprecation and some conditional code
will be added as a last resort attempt to preserve behavior
compatibility while moving forward with breaking changes.
2020-02-08 17:18:01 -05:00
Emmanuel Lepage Vallee d2f8999595 init: Support loading awesome with shebang (#!) executables.
This commits re-use the modeline code from the previous commit
to support Lua scripts starting with #!. Previously, it was
non-trivial to add support since most *nix OS wont parse the
command line arguments correctly. Since we now have a state
machine good enough for 95%+ of the use case, it is easy to
support them.
2020-02-08 17:18:01 -05:00
Emmanuel Lepage Vallee f1aedb237a init: Add modeline support.
This commits adds the ability to add an `-- awesome_mode:` comment
to `rc.lua`. This line will be interpreted before Lua starts and
allow command line options to be set in the file.

There is also a partial shebang mode (`#!`) support. While it is
not yet possible to make a random Lua file executable and start
`awesome`, it is at least supported to configure AwesomeWM. The
next commit will add the missing bits.

This commit implements the parsing using a state machine. While
glib has its own functions, they don't do 100% of what we need.
It could have been possible to use them anyway and get quotes,
escaping and UTF-8 support for free. The downside would have been
duplicated code to handle shebangs and modeline. The state machine
code fully support 3 different ways of loading the arguments with
the same code path.
2020-02-08 17:17:59 -05:00
Emmanuel Lepage Vallee af4b4a254f init: Move the command option parsing to its own file.
The next commit will add modeline support and share the code.
2020-02-04 01:50:02 -05:00
Aire-One 4b66bb935c Allow `getopt_long` call to manage the `-m` option (short of `--screen`). 2019-09-30 15:53:21 +02:00
Emmanuel Lepage Vallee 1304f46c0c screen: Split the `outputs` code away from the screen logic.
It moves the actual place where when screen array is stored into the
area object. This allows to store the outputs when screens are not
automatically created.
2019-09-29 18:56:06 -04:00
Emmanuel Lepage Vallee f6cc35cecc screen: Disable screen creation when --screen manual is used.
Now that the previous commits add a proper fallback and a way to test
this, enable the second half.

As long as the default screen mode (`--screen auto`) *or* the `rc.lua`
doesn't execute too much code in the global context, this wont break
much.
2019-09-29 18:56:06 -04:00
Emmanuel Lepage Vallee 433898599d init: Add a command line option to start AwesomeWM without screens.
This commit add an optional `--screen off` command to initialize Lua
without first adding the screens. This is inconvinient for most users
since it restrict the APIs that are usable out of the box.

However, this allows AwesomeWM to work independently from the hardware.
This means that when a screen is unplugged, it is the Lua code that will
remove the screen instead of CAPI pulling the carpet from under. It also
allows to ignore some screen areas before the screen is ever created.
Combined, it makes it possible to work with screens even when they are
physically disconnected. Finally, it will allow for an awful.rules like
API to control how screens are created.

All in all, some people need this for their setup and some people might
want to do it anyway for fine grained and/or dynamaic multi-screen
setups.

This commit also adds 4 new signals to `capi` to be able to
execute code at specific points during the initialization. The commit
improves naughty error notifications to work even if problems occurs
before the screens are added.

Note that AwesomeWM will exit if no screens are created. While it would
be easy to just call `refresh_screen();` after unsetting the magic
variable, doing so would have corner cases. Better be harsher and
prevent the user from shooting themselves in the foot from not reading
the f****** manual. Code introduced in future commits will take care
of automatically calling fake_screen in the event nothing is created.

Fixes #1382
2019-09-29 18:52:00 -04:00
Uli Schlachter a57c79687a Use xcb-errors library if it is available
This library allows to get a human-readable string describing X11
requests, events, and errors. We now use this library to pretty-print
X11 errors if we get any.

To test this code, I added the following two lines to AwesomeWM so that
X11 errors are generated:

    xcb_set_input_focus(globalconf.connection, 42, 42, 42);
    xcb_randr_set_output_primary(globalconf.connection,
        globalconf.screen->root, 42);

Output without xcb-errors:

    X error: request=SetInputFocus (major 42, minor 0), error=BadValue (2)
    X error: request=(null) (major 140, minor 30), error=(null) (147)

Output with xcb-errors:

    X error: request=SetInputFocus (major 42, minor 0), error=Value (2)
    X error: request=RandR-SetOutputPrimary (major 140, minor 30), error=RandR-BadOutput (147)

Signed-off-by: Uli Schlachter <psychon@znc.in>
2019-03-03 09:15:29 +01:00
Uli Schlachter aa21156ced Make sure we always flush after xcb_ungrab_server()
Between xcb_grab_server() and xcb_ungrab_server(), XCB's output buffer
might fill up. Thus, the GrabServer request might already have been sent
to the server, but the following UngrabServer request could end up in
XCB's output buffer. There, it might sit around for quite a while and
cause problems.

Since we cannot detect when XCB's output buffer fills up, we just always
flush after generating an UngrabServer request.

Very-likely-Fixes: https://github.com/awesomeWM/awesome/issues/2697
Signed-off-by: Uli Schlachter <psychon@znc.in>
2019-02-27 10:20:22 +01:00
Uli Schlachter 3a4bf103b3 Initialise Lua's pseudo-RNG from C from a good source
GLib has an internal pseudo-RNG that it initialises from /dev/urandom.
This commit adds code that uses this RNG to initialise various random
number generators that can be used by Lua.

This also removes some Lua code that initialises the random number
generator badly.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2019-02-17 10:17:47 +01:00
Uli Schlachter 2023ed187a Add xcb-xfixes as a new dependency and initialise it
This commit prepares changes in the following commits

Signed-off-by: Uli Schlachter <psychon@znc.in>
2019-02-06 09:21:26 +01:00
Daniel Hahler aaed083755 signal_child: use "(void) res" to silence compiler warning
Fixes https://github.com/awesomeWM/awesome/issues/2418.
2018-10-06 22:49:29 +02:00
mergify[bot] 69bb30181d
Merge pull request #2367 from psychon/poll_save_errno
a_glib_poll: Preserve errno from g_poll()
2018-08-26 16:40:06 +00:00
Uli Schlachter e907f44db9 a_glib_poll: Preserve errno from g_poll()
When poll() is interrupted because of a signal, it sets errno to EINTR.
GLib ignores this kind of failure.

However, a_glib_poll() calls a_xcb_check() at its end. This will call
xcb_poll_for_event() which internally might call recv(), which can fail
with EAGAIN if no new events are available. Thus, a_glib_poll() will
return an error and set errno to EAGAIN. This leads to the following
error message being printed by GLib:

  GLib-WARNING: poll(2) failed due to: Resource temporarily unavailable.

Fix this by preserving the errno from g_poll() in a_glib_poll().

Signed-off-by: Uli Schlachter <psychon@znc.in>
2018-08-21 15:30:58 +02:00
Uli Schlachter 6c559e188c Handle SIGCHLD ourselves instead of through GLib
GLib is very careful not to "fetch" any children that it was not asked
to fetch. Thus, if awesome inherits some children, it does not reap them
and starts collecting zombies.

Thus, this commit makes awesome handle SIGCHLD directly: On SIGCHLD, a
byte is written to a pipe. The main loop reads from this pipe and
collects children via waitpid(-1). Unknown children cause a warning to
be printed. We might want to remove this warning if it turns out to be
annoying.

This commit adds 79 lines and removes 89 lines. Thus, this is a net
reduction in lines of codes. This is because previously, we gave the
list of still-running children that we know about to the next awesome
instance we a --reap command line argument. This was added so that
awesome does not get zombie children. However, this commit fixes this
problem and makes all the code for this 'feature' unnecessary.

Fixes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=886393
Signed-off-by: Uli Schlachter <psychon@znc.in>
2018-08-21 15:30:07 +02:00
Uli Schlachter c9bd787fd6 Check for xdgInitHandle() failures (#2146)
Before this, running "env -i ./awesome" resulted in a segfault. This was
because xdgInitHandle() failed and the following
xdgSearchableConfigDirectories() followed a NULL pointer.

After this commit, awesome fails with an error message.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2018-01-12 21:33:25 -05:00
Uli Schlachter e7982b7aba Reduce some variable scopes
Codacy things this is a good idea...

Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-11-17 10:30:56 +01:00
Uli Schlachter af8288335b Use command line instead of env for passing children
Commit e54361a374 added code so that we pass the list of
currently running children across restart via an environment variable.
As Colin Walters correctly points out, setenv() is not safe in a
multi-threaded processes.

Thus, instead of using the environment, use the command line to pass
this information along.

https://github.com/awesomeWM/awesome/issues/1812
Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-06-04 16:04:44 +02:00
Uli Schlachter d799eea2cf Restart by calling execvp() directly
Before this, we used a_exec() with started a shell and used it to parse
our glued-together command line. That only asks for escaping trouble
(think: Path to the config file is given on the command line and
contains a space), so use execvp() directly.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-06-04 16:04:44 +02:00
Uli Schlachter e54361a374 Reap children even across a restart
In Unix, so that a process can learn about the exit status of the child
processes that it started, children become zombie processes until the
parents collects their exit information. We use glib both for starting
and for collecting processes. However, when awesome is restarted, the
new instance inherits children, but does not know about them and does
not inherit them.

Fix this by explicitly tracking a list of running child processes and by
serialising them across a restart via an environment variable. The new
awesome instance can then watch for these child processes, but besides
that it ignores them and does not use their exit status in any way.

Thanks to Colin Walters for the hint with serialising the list of processes.

Fixes: https://github.com/awesomeWM/awesome/issues/1193
Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-06-01 15:47:24 +02:00
Uli Schlachter 29aee713f3 Remove most uses of XCB_CURRENT_TIME
XCB_CURRENT_TIME really should be avoided as much as possible (see
ICCCM).

However, the screen, mousegrabber and keygrabber code have cases where
they really want up-to-date information / want to activate a grab *now*.
These cases are fine with XCB_CURRENT_TIME since they are not related to
some events.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-04-15 14:50:44 +02:00
Uli Schlachter 5d83eee16f Initialize globalconf.timestamp at startup
There are lots of places where ICCCM says that using CurrentTime for a
timestamp is wrong. So, instead of having globalconf.timestamp
initialized to CurrentTime, initialize it with a proper timestamp.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-04-15 11:46:10 +02:00
Emmanuel Lepage Vallée cbd22eea50 Merge pull request #1475 from psychon/input-shape-support
Input shape support
2017-02-03 12:25:56 -05:00
Uli Schlachter 64e05c236f xwindow: Add support for input shape from SHAPE 1.1
Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-01-26 10:45:24 +01:00
Uli Schlachter b4b007796c Initialise Lua later
This moves Lua initialisation to the latest possible point, just before
loading the configuration file. This requires to also move screen
initialisation and parts of EWMH initialisation to a later point.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-01-25 14:55:27 +01:00
Uli Schlachter 95b1305613 Refactor config fallback
Before this, there was a function which attempted to load different
configuration files in the right order. There was a boolean argument
that decided if we are actually loading it or just checking for syntax
error (for the --check argument of awesome). This lead to some
not-so-nice code since we do not want to fall-back to another config
when checking for syntax errors.

Refactor this so that there is now a function which calls a callback
function with the different paths that should be tried. This function
returns as soon as the callback function returns true.

Since just checking if the config syntax is ok does not depend on any
Lua state, an empty Lua state is now used for this.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-01-25 14:10:19 +01:00
Uli Schlachter 89202529ea Move some code from luaa.c to awesome.c
It makes more sense to append the xdg config dirs to our list of
searchpath in awesome.c than in luaa.c. Plus, it simplifies some of the
following work.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-01-25 13:50:52 +01:00
Uli Schlachter 4c322a613f Ignore SIGPIPE
When the child process in tests/_client.lua breaks and exits (for
example: Remove the call to Gtk.main), we get a broken pipe. When trying
to write to the pipe that connects awesome to the child process, we get
a SIGPIPE signal that causes awesome to exit without any good error
message.

Fix this by ignoring SIGPIPE. We do not want to be killed by it anyway.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-01-02 16:06:04 +01:00
Uli Schlachter 13e8088d62 Handle unexpected XCB failures (#1260)
We have many places where we are sending an XCB request and expect an
answer where the protocol guarantees that no error can occur and we are
sure to get an answer. However, for example if the X11 server crashes,
these places can still fail. This commit tries to handle failures at all
these places.

I went through the code and tried to add missing error checking (well,
NULL-pointer-checking) to all affected places.

In most cases these errors are just silently ignored. The exception is
in screen querying during startup. If, for example, querying RandR info
fails, we will fall back to Xinerama or zaphod mode. This is serious
enough that it warrants a warning. In most cases, we should exit shortly
afterwards anyway, because, as explained above, these requests should
only fail when our connection to the X11 server breaks.

References: https://github.com/awesomeWM/awesome/issues/1205#issuecomment-265869874
Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-12-10 00:48:53 +01:00
Uli Schlachter c7423fe79e Really stop using Xlib
Apparently I forgot some part...?

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-11-04 17:21:06 +01:00
Uli Schlachter 0e81479a3f Use xcb-util-xrm
Instead of using Xlib for parsing resource files, this now uses the
dedicated xcb-based library that is meant for exactly this task.

Fixes: https://github.com/awesomeWM/awesome/issues/1176
Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-11-03 13:34:43 +01:00
Uli Schlachter d71bb665d1 awesome.quit(): Add exit code argument (#1192)
Fixes: https://github.com/awesomeWM/awesome/issues/1184
Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-10-27 10:40:53 +02:00
Uli Schlachter 3bd045b57c Check for pending events after the main loop (#1163)
At the beginning of every main loop iteration, we check for new events
from the X11 server. However, it's theoretically possible that during a
main loop iteration new events arrive and are read by libxcb into its
internal buffer. This would mean that the fd connected to the X11 server
is not readable and thus we do not wake up to handle these events.

Handle this by checking for pending events before calling poll(). If a
new events appears, we set the timeout for poll() to zero and will then
handle the new event in the following iteration of the main loop.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-10-22 10:46:49 +02:00
Uli Schlachter e1d5c0c925 Do not allow multiple --config arguments
Otherwise there is a small, unimportant memory leak. More important is the fact
that later such flags overwrite earlier flags.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-08-31 13:31:16 +02:00
Uli Schlachter 4cbf87b441 Remove empty-argument checks
This code removes code which could only be hit be running awesome --search '' or
awesome -c ''. In both cases there are many possibilities for weird/invalid
arguments and I don't see why the empty string deserves special treatment.

Note that awesome --search does NOT hit this code, because getopt_long handles
the case of "completely missing" arguments itself.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-08-31 13:27:07 +02:00
Uli Schlachter fd90061c24 Make argument parsing errors fatal
When you run "awesome --foobar", a warning will be printed (by getopt_long())
and awesome just ignores the invalid argument. That's unusual and weird.

This commit produces an error instead.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-08-31 13:26:28 +02:00
Uli Schlachter 24bb38969d Add an option to add a path to $LUA_PATH
The same effect could be achieved by modifying $LUA_PATH or with symlinks, but
having a special option to do this seems easier.

Note that the man page translations were generated via Google translate. I'm
looking forward to people submitting correct translations...

Inspired-by: https://github.com/awesomeWM/awesome/pull/485
Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-08-20 16:04:11 +02:00
Uli Schlachter 80a6f2f510 Clean up static variables in event_handle
This function needs the event numbers for events from some extensions. These are
assigned dynamically by the server. Right now, this is done by having a bunch of
static variables that are initialized when needed.

Refactor this to have a function event_init() instead that sets variable in
globalconf (where all of our state should be saved). Also, a preprocessor macro
is introduced to handle event dispatch which also looks a bit nicer.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-04-09 15:44:54 +02:00
Uli Schlachter 9ea207afaa Revert "Only define screens after the config is loaded"
This reverts commit e6037b4738. It causes many
issues with non-trivial solutions that we first need to come up with. As a
middle ground, we will for now only emit signals if something changes after the
config is loaded.

See https://github.com/awesomeWM/awesome/issues/799.
2016-04-05 08:53:14 +02:00
Daniel Hahler 3e5b1b3ba9 Merge pull request #782 from psychon/wallpaper-change
Changes to wallpaper change
2016-04-03 18:35:27 +02:00
Uli Schlachter 3117b439a2 Cache the wallpaper
Instead of querying the wallpaper every time that root.wallpaper() is called, we
just remember it in globalconf.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-03-27 11:45:08 +02:00
Uli Schlachter e6037b4738 Only define screens after the config is loaded
This gives us the worst of both worlds: We still restart on RandR screen changes
and the information about screens isn't available during startup. However, it's
a step in the right direction, because all Lua code will now have to handle
kind-of-dynamic screen changes.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-03-27 10:51:28 +02:00
Emmanuel Lepage Vallee 03f5f5b7f9 cmd: Document --no-argb in --help 2016-03-22 03:27:59 -04:00
Uli Schlachter 68691ff818 Check that the Lua stack is empty in the main loop
The Lua stack is a finite resource and everything that pushes something there
should also clean up. This is not a problem for functions that are called by
Lua, because their "stack frame" is freed when they return. However, in global
context, Lua does not and cannot automatically clean up for us. Thus, it makes
sense to print a warning in this case.

(Additionally, this cleans up the stack if something is left)

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-02-17 18:40:01 +01:00
Uli Schlachter 4ad516c63a Remove some unused fields from globalconf
These fields were only ever written to since commit 19137a55c3.
This commit removes the fields and the code that sets them.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-12-22 17:25:45 +01:00
Lukáš Hrázký ea94f7f7e6 add an option to set the preferred client icon size
_NET_WM_ICON contains a list of icons and until now, the first one was
picked without regard to it's size. This adds a global option to set
the preferred icon size. When getting the client icon, the best size
match is picked. The size can be set via
awesome.set_preferred_icon_size() and the default is 0, which will pick
the smallest non-zero size icon available.

Signed-off-by: Lukáš Hrázký <lukkash@email.cz>
2015-12-07 22:59:32 +01:00
Uli Schlachter 6ca85af53b Set WM_CLASS and WM_NAME on all our windows (#551)
The only exception is the window for _NET_SUPPORTING_WM_CHECK. That window
already had a _NET_WM_NAME property before and doesn't get a WM_NAME property in
this commit. I just decided for myself that it doesn't need one. :-)

Right after startup with the default config we now have the following situation:

$ xwininfo -root -tree

xwininfo: Window id: 0x2d7 (the root window) (has no name)

  Root window id: 0x2d7 (the root window) (has no name)
  Parent window id: 0x0 (none)
     7 children:
     0x200011 "Awesome drawin": ("awesome" "awesome")  1500x20+0+0  +0+0
     0x200010 "Awesome drawin": ("awesome" "awesome")  1x1+0+0  +0+0
     0x20000d "Awesome drawin": ("awesome" "awesome")  100x30+0+0  +0+0
     0x20000a "Awesome no input window": ("awesome" "awesome")  1x1+-1+-1  +-1+-1
     0x200009 "Awesome systray window": ("awesome" "awesome")  1x1+-1+-1  +-1+-1
     0x200008 "awesome": ("awesome" "awesome")  1x1+-1+-1  +-1+-1
     0x200007 "Awesome WM_Sn selection owner window": ("awesome" "awesome")  1x1+-1+-1  +-1+-1

One of those drawin is the awful.wibox. Another drawin is created by awful.menu.
I guess that the third one is created by awful.tooltip, but I'm not sure. Wow,
so many windows...

Closes https://github.com/awesomeWM/awesome/pull/556.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-11-19 22:23:25 +01:00
Uli Schlachter 33f8a06594 Document "--replace" better
This adds it to the output of "awesome -h" and translates the version in the man
page to italian. Thanks, eri_trabiccolo for the translation!

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-10-11 15:00:08 +02:00