Commit Graph

732 Commits

Author SHA1 Message Date
Uli Schlachter 9566defa93 C: Add a .data table to all C objects
This table is "just a normal Lua table". Lua code can use it in whatever
way it wants to store things related to a given C object.

An object (userdata) already references a "plain Lua table" via
lua_setuservalue() / lua_setfenv(). This is used to keep a reference to
signal functions that are connected to an object. The signal code only
uses lightuserdata keys in this table. This commit adds an entry with
key "data" to this table which just references another table. This is
the table that is made available as .data.

Via this .data property, Lua code can add own properties to C objects
without having to use, for example, weak tables. The weak tables have
the downside that they produce a leak if the value references the key.
The new .data property does not have any such problem (no weak
references are involved).

This new data property is not documented, because I'd have to touch lots
of files and I'm lazy.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-09-30 11:07:55 +02:00
Uli Schlachter 489aa4dc24 Improve behaviour of GC'd objects
Before this commit: When we are GC'ing an object, we clear its metatable, since
otherwise crashes could occur in various places. This means that if someone
tries to use such an object, they get an unhelpful error message like "attempt
to index userdata object" and they don't understand what the problem is. Also,
this means that foo.valid does not actually work after GC.

This commit changes this behaviour. Instead of setting an empty metatable, we
now create a metatable with an __index and __newindex method. These metamethods
produce better error messages that they sat the underlying object was already
garbage collected. Better yet, the __index metamethod makes foo.valid be false
instead of causing an error, so that the existing machinery for detecting
invalid objects continues to work.

This commit also adds a functional test that verifies this behaviour.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-09-24 14:37:07 +02:00
Uli Schlachter 75ed165ae6 Test & fix a bug with dbus.disconnect_signal (#1096)
The code was written so that it assumes that disconnecting the last signal also
removed the corresponding entry in the signal array. This lead e.g. to an
index-out-of-bounds access in some cases.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-09-18 12:50:40 +02:00
Uli Schlachter 896eee8b1f Print LuaJIT version in --version (#996)
When called with "--version", awesome prints the Lua version that it was
compiled against and the one that it is running against. This commit makes the
code detect LuaJIT and makes it print the LuaJIT version instead of an
unspecific "Lua 5.1".

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-07-09 19:05:44 +02:00
Uli Schlachter 6f1df7a3ad Fix disconnecting not connected signals (#950)
When a function is disconnected from a signal ("disconnect_signal") that is not
actually connected to the function, two things happened:

1. The attempt to remove the function from the signal array didn't do anything
2. Unreferencing the function noticed that the function wasn't referenced

The second step printed a big, fat scary warning.

Actually, this has the possibility of causing errors. For example, in the
following code, awesome would wrongly unreference the function at the
disconnect_signal() call and might later still try to call it when the
"refresh" signal is emitted:

do
    local function f() end
    awesome.connect_signal("refresh", f)
    awesome.disconnect_signal("debug::error", f)
end

Fix this by making signal_disconnect() return a boolean value indicating if it
actually did something. All callers are fixed to use this value and only update
the reference counts if something was actually disconnected.

Fixes: https://github.com/awesomeWM/awesome/issues/814
Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-06-09 00:03:08 +02:00
Uli Schlachter 231436d9e3 C: Remove unneeded calls to signal_add()
Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-06-04 17:57:08 +02:00
Uli Schlachter a964396771 Deprecate signal_add() on C-API objects
This commit makes the code automatically add signals when they are first used.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-06-04 17:51:45 +02:00
Uli Schlachter 270baeb153 "Fix" client properties which can be absent (#932)
A client c could have no c.machine or no c.pid because the corresponding
properties are not set on its window. Previously, the C code would return an
empty string or 0 for these values. This commit makes the C code give Lua no
value instead (not even a nil).

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-06-04 00:51:23 +02:00
Uli Schlachter ec076ca4bd Properly support the XEMBED_MAPPED bit
The XEmbed protocol defines a special property that defines if the embedded
window wants to be visible or not. Up to now, awesome always ignored this entry
and instead behaved as if the bit was set. This commit makes it properly respect
the bit.

Testing done: None. No idea how. Apparently nothing really uses this bit,
because we didn't get bug reports about it yet.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-05-31 08:55:42 +02:00
Uli Schlachter 2cf4ea5cd4 xutil.h: Add defines for valid coordinates and sizes
Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-04-17 13:48:24 +02:00
Uli Schlachter 93e50b2e23 Merge branch 'lua-index-handlers' of https://github.com/psychon/awesome 2016-03-06 14:19:00 +01:00
Uli Schlachter f02b75f826 Fix arguments to luaL_checkstack()
The argument to luaL_checkstack() is the amount of new stack to make available,
not the new size of the stack. Thus, remove the addition of lua_gettop(L) here.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-02-17 19:07:06 +01:00
Uli Schlachter d09ece6b5a Require "integer" instead of "number" in more places
E.g. trying to press mouse button 1.5 via root.fake_input() doesn't make sense.
Previously the code silently truncated the number to an integer. Now it
complains about this instead.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-02-06 13:59:14 +01:00
Uli Schlachter 051d0de85f Replace many pushnumber calls with pushinteger
The only remaining calls are for a window's opacity and in the DBus type
handling. Everything else wants integers, not something with a comma.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-02-06 13:46:46 +01:00
Uli Schlachter 44fcfa2d48 Remove prototype of xutil_lock_mask_get()
This function was removed in 4ad516c63a, but I forgot to also remove it
from header. Whoops...

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-01-23 17:12:10 +01:00
Uli Schlachter 720cd879f3 Add timestamps to messages on stderr (#602)
Closes https://github.com/awesomeWM/awesome/pull/606.
Fixes https://github.com/awesomeWM/awesome/issues/602.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-12-31 15:38:17 +01:00
Uli Schlachter 5e6a893207 Replace various calls to warn() with luaA_warn()
luaA_warn() prints a Lua backtrace and thus generates more useful output. warn()
should only be used in awesome-internal places (e.g. receiving an error from the
X11 server).

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

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-12-31 15:35:13 +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
Uli Schlachter a141370704 Add a vim modeline to all C source
Most of the files already had this, at least.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-12-12 17:42:16 +01:00
Uli Schlachter 97048de60e Remove useless information from awesome -v
Most of this information isn't interesting. If you are getting awesome from a
distro, then the time, hostname and username of the build are likely 'random
stuff' and if you are building awesome yourself, then the hostname and username
are obviously yours and the time can still be interfered based on the awesome's
binary ctime.

The GCC version shouldn't make any difference at all.

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

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-12-01 20:17:21 +01:00
Kazunobu Kuriyama 2f7f25dcc7 Fix the definition of A_STRNEQ_CASE
Replace A_STRCASEEQ whose definition is not given anywhere with A_STREQ_CASE.

Closes https://github.com/awesomeWM/awesome/pull/488.
2015-09-28 23:34:52 +02:00
Uli Schlachter a5a106f97f Make it possible for Lua to emulate arbitrary properties
This makes it possible to add something similar to a __index / __newindex
metamethod to all our C objects. Based on this, Lua can then easily implement
arbitrary properties on our capi objects.
2015-09-27 17:43:41 +02:00
Daniel Hahler 481cd8f843 minor: doc: fix typo in buffer_init 2015-07-28 19:31:51 +02:00
Uli Schlachter c945492176 Keep client order across restarts
This saves the order of clients in a property called AWESOME_CLIENT_ORDER on the
root window during shutdown. During startup, after managing all existing
windows, we force the client list into the order described by this property
(overwriting any changes that Lua possibly did).

This code should safely handle cases where the property doesn't contain all
existing clients or contains a client which doesn't exist anymore.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-07-27 13:47:09 +02:00
Daniel Hahler 3cd0bb5783 common/array.h: add macro `foreach_reverse`
Ref: https://github.com/awesomeWM/awesome/pull/340
2015-07-25 16:42:50 +02:00
Daniel Hahler 1050237d04 minor: fix/improve doc comments 2015-07-12 17:42:53 +02:00
Uli Schlachter 55bffbcc45 Fix for previous commit
Forgot to commit the change that adds _NET_FRAME_EXTENTS to the list of atoms
that we actually query for and export to the C code.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-07-05 15:34:23 +02:00
Daniel Hahler d4d5bbcd5d Merge pull request #266 from awesomeWM/juw-docs
docs: move documentation to C source
2015-06-21 21:33:22 +02:00
Uli Schlachter 1408e8b952 Unset object's metatable in __gc
Run the following code:

  do
      local d
      local f = function() d.visible = true end
      if _VERSION >= "Lua 5.2" then
          setmetatable({}, { __gc = f })
      else
          getmetatable(newproxy(true)).__gc = f
      end
      d = drawin({})
  end
  collectgarbage("collect")

Awesome will segfault.

The reason for this is that after the above code ran, all variables in it are
unreferenced and will be garbage-collected at the next sweep phase. Lua runs
garbage collectors in the inverse order that their corresponding objects were
"marked" which means for the above code that the drawin's garbage collector will
run before function f runs. So the code will access the drawin after its
destructor already ran. Obviously, awesome's C code does not expect nor
correctly deal with this situation and was dereferencing a NULL pointer.

To fix this, this commit "unsets" the metatable of a userdata object when it is
being garbage collected. Since the type of a userdata is inferred via its
metatable, the object will no longer be accepted by luaA_toudata().

For the above code this will result in an unhelpful error message saying that
something tried to index a userdata, but userdata cannot be indexed. At least we
no longer crash and the traceback of the error will hopefully point at some __gc
metamethod which should be enough of a hint to figure out the problem.

Thanks-to: http://blog.reverberate.org/2014/06/beware-of-lua-finalizers-in-c-modules.html
Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-06-20 12:33:17 +02:00
Julian Wollrath 26f15a13f3 Document C API directly in the C source code
v2: Add available signals to the docs.

Signed-off-by: Julian Wollrath <jwollrath@web.de>
2015-06-19 23:13:31 +02:00
Uli Schlachter f5610fa920 objects: Add .valid property (Fixes #110)
This property is especially useful for client objects which are unusable after
unmanage. "Unusuable" here means that pretty much everything you do with the
client object results in a lua error.

Syntax is c.valid.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-02-15 12:16:03 +01:00
Daniel Hahler f562b4a64b luaA_object_emit_signal: check for valid object
By the time a signal gets emitted the object might be invalid already,
e.g. when it is very short-lived and unmanaged by the time the delayed
call to emit_signal is being invoked.

Ref: https://github.com/awesomeWM/awesome/pull/87#issuecomment-70901168
2015-02-10 14:52:47 +01:00
Uli Schlachter 8eed5e7bcf client: Include c.name in the result of tostring(c)
Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-12-06 18:16:05 +01:00
Uli Schlachter a7cdbf468b Only include awesome-version-internal.h in one place
This means we have one less file which gets recompiled every time the result
from "git describe" changes.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-04-13 17:48:03 +02:00
Uli Schlachter d2b1e92f9e Clean up header includes
Every .c file has to include the corresponding .h file first to make sure the
headers are self-contained. Additionally, this moves some unneeded includes
around.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-03-30 20:07:48 +02:00
Uli Schlachter 1b21dce46c Revert "client: Add c.blob property"
This reverts commit a54636751b.

We now have the new xproperty API which does the same thing in a much nicer way.
Thanks to Elv13 for the idea!

Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-03-07 16:21:11 +01:00
Uli Schlachter 2b1febeabe Make objects properly inherit signals from classes
Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-03-07 14:42:03 +01:00
Uli Schlachter a54636751b client: Add c.blob property
Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-02-23 12:26:13 +01:00
Uli Schlachter 1703801728 ewmh: remove _NET_DESKTOP_GEOMETRY support
Our tag concept doesn't really fit into ewmh. Thus, we were setting this
property to a way too small value anyway (just the size of the first screen in
case of multiple screens).

Since this property is optional in ewmh, let's just drop it.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2013-09-27 23:01:49 +02:00
Uli Schlachter 381d840a82 Use $PATH when starting $SHELL
If $SHELL is set to "bash", previously awesome failed to restart itself, because
it could not find "bash". This commit makes awesome use execlp() instead of
execl() which means that $PATH is searched if the started command does not
contain a slash and this problem is fixed.

$SHELL is specified in POSIX and it doesn't seem to require an absolute path
name.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2013-09-27 16:22:55 +02:00
Uli Schlachter aaa771f887 Switch from libXcursor to libxcb-cursor
Thanks to Michael Stapelberg, there is now a xcb-only port of libXcursor which
does everything we need. This patch switches awesome over to that new library.

Since the only reason for using XOpenDisplay() instead of xcb_connect() was so
that we can use libXcursor, we can get back to that older state again. This
means that this effectively reverts the following commits:

531f8b415c "Added initial support for Xlib cursor themes"
77243cd09a "Add x11-xcb to the pkg-config checks"
779d43fc46 "Don't let Xlib own the event queue"
03759b4847 "Fix keyboard layouts"

Signed-off-by: Uli Schlachter <psychon@znc.in>
2013-09-19 16:48:10 +02:00
Gregor Best a2cd466103 Remove compiler warnings
Signed-off-by: Gregor Best <gbe@ring0.de>
Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-11-24 18:15:34 +01:00
Tumin Alexander 531f8b415c Added initial support for Xlib cursor themes
I hope this time i got all right with git format-patch.

Signed-off-by: Tumin Alexander <iamtakingiteasy@eientei.org>
Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-10-07 12:39:56 +02:00
Arvydas Sidorenko c491cd034c common/util.h: dodgy non-__GNUC__ p_delete
I assume nobody have tried to compile Awesome with GNU uncompatible
compiler for ages and thus non-__GNUC__ p_delete version got
overlooked for quite some time.
First of all, a problem I see is that it assigns void** to a variable
of type void* and then dereferences the same void* variable.
None of the compilers I am aware of will let you go through this
without an error.
And second of all, lets have one portable p_delete.

Signed-off-by: Arvydas Sidorenko <asido4@gmail.com>
Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-07-31 16:33:05 +02:00
Uli Schlachter 2853d58f52 root: Add a wallpaper setter
This allows lua code to set a wallpaper directly instead of having to spawn some
external tools which possibly aren't installed.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-07-29 15:32:04 +02:00
Uli Schlachter 05a8ef2ed9 Handle execv() errors
Previously, awesome would just crash when execv() fails, because it already
destroyed all of its internal state, but then tries to do another main loop
iteration. Whoops.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-07-15 00:18:44 +02:00
Arvydas Sidorenko f41590e19c Wrapped luaL_register
Signed-off-by: Arvydas Sidorenko <asido4@gmail.com>
Signed-off-by: Julien Danjou <julien@danjou.info>
2012-06-12 13:32:40 +02:00
Arvydas Sidorenko 508dce9c14 Replaced already in Lua 5.1 deprecated lua_open()
In Lua 5.1 lua_open directly calls luaL_newstate, but was deprecated.
In Lua 5.2 lua_open was removed.

Signed-off-by: Arvydas Sidorenko <asido4@gmail.com>
2012-06-12 11:07:15 +02:00
Arvydas Sidorenko d612b922f3 lua_objlen wrapped in luaA_rawlen
In lua 5.2 lua_objlen was renamed for now reason

Signed-off-by: Arvydas Sidorenko <asido4@gmail.com>
2012-06-12 11:02:57 +02:00
Arvydas Sidorenko 47e21ad3cc Wrapped lua_[gs]etfenv into luaA_[gs]etuservalue
Lua 5.2 removed lua_[gs]etfenv and introduced
lua_[gs]etuservalue. Not sure though if it provides
the required functionality which awesome is using.
Thus, need some testing.

Signed-off-by: Arvydas Sidorenko <asido4@gmail.com>
2012-06-12 11:02:34 +02:00