From 2d511e2ab555fa3d08c88ca7be6eff2043c516b9 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 4 Jun 2016 15:56:52 +0200 Subject: [PATCH] gears.object.properties: Implement read-only properties Signed-off-by: Uli Schlachter --- lib/awful/screen.lua | 14 -------------- lib/gears/object/properties.lua | 5 +++++ tests/test-miss-handlers.lua | 4 ++++ 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/lib/awful/screen.lua b/lib/awful/screen.lua index 9073dd9f..162628cf 100644 --- a/lib/awful/screen.lua +++ b/lib/awful/screen.lua @@ -311,8 +311,6 @@ function screen.object.get_clients(s) return vcls end -function screen.object.set_clients() end - --- Get the list of the clients assigned to the screen but not currently -- visible. -- @@ -335,8 +333,6 @@ function screen.object.get_hidden_clients(s) return vcls end -function screen.object.set_hidden_clients() end - --- Get all clients assigned to the screen. -- -- @property all_clients @@ -349,8 +345,6 @@ function screen.object.get_all_clients(s) return capi.client.get(s, true) end -function screen.object.set_all_clients() end - --- Get the list of the screen tiled clients. -- -- Same as s.clients, but excluding: @@ -377,8 +371,6 @@ function screen.object.get_tiled_clients(s) return tclients end -function screen.object.set_tiled_clients() end - --- Call a function for each existing and created-in-the-future screen. -- @function awful.screen.connect_for_each_screen -- @tparam function func The function to call. @@ -425,8 +417,6 @@ function screen.object.get_tags(s, unordered) return tags end -function screen.object.set_tags() end - --- A list of all selected tags on the screen. -- @property selected_tags -- @param table @@ -446,8 +436,6 @@ function screen.object.get_selected_tags(s) return vtags end -function screen.object.set_selected_tags() end - --- The first selected tag. -- @property selected_tag -- @param table @@ -459,8 +447,6 @@ function screen.object.get_selected_tag(s) return screen.object.get_selected_tags(s)[1] end -function screen.object.set_selected_tag() end - --- When the tag history changed. -- @signal tag::history::update diff --git a/lib/gears/object/properties.lua b/lib/gears/object/properties.lua index 9b988682..f528482a 100644 --- a/lib/gears/object/properties.lua +++ b/lib/gears/object/properties.lua @@ -83,6 +83,11 @@ function object.capi_index_fallback(class, args) return args.setter_fallback(cobj, prop, value) end + -- If a getter exists but not a setter, then the property is read-only + if args.getter_class and args.getter_class[getter_prefix..prop] then + return + end + local fallback = properties[cobj] or cobj_register(cobj) -- Use the fallback property table diff --git a/tests/test-miss-handlers.lua b/tests/test-miss-handlers.lua index 258cbb99..46cfad2c 100644 --- a/tests/test-miss-handlers.lua +++ b/tests/test-miss-handlers.lua @@ -40,4 +40,8 @@ local w = wibox() w.foo = "bar" assert(w.foo == "bar") +-- Test if read-only properties really are read-only +screen[1].clients = 42 +assert(screen[1].clients ~= 42) + require("_runner").run_steps({ function() return true end })