- /* If the key handling is turned off, don't do anything */
- if (handle == HANDLE_IGNORE) {
- log_debug("Refusing key handling, as it is turned off.");
- return 0;
- }
-
- /* If the key handling is inhibited, don't do anything */
- if (manager_is_inhibited(b->manager, inhibit_key, INHIBIT_BLOCK, NULL, true, false, 0)) {
- log_debug("Refusing key handling, %s is inhibited.", inhibit_what_to_string(inhibit_key));
- return 0;
- }
-
- inhibit_operation = handle == HANDLE_SUSPEND || handle == HANDLE_HIBERNATE ? INHIBIT_SLEEP : INHIBIT_SHUTDOWN;
-
- /* If the actual operation is inhibited, warn and fail */
- if (!ignore_inhibited &&
- manager_is_inhibited(b->manager, inhibit_operation, INHIBIT_BLOCK, NULL, false, false, 0)) {
-
-
- /* If this is just a recheck of the lid switch then don't warn about anything */
- if (!is_edge) {
- log_debug("Refusing operation, %s is inhibited.", inhibit_what_to_string(inhibit_operation));
- return 0;
- }
-
- log_error("Refusing operation, %s is inhibited.", inhibit_what_to_string(inhibit_operation));
- warn_melody();
- return -EPERM;
- }
-
- log_info("%s", message_table[handle]);
-
- /* We are executing the operation, so make sure we don't
- * execute another one until the lid is opened/closed again */
- b->lid_close_queued = false;
+ r = manager_handle_action(b->manager, inhibit_key, handle, ignore_inhibited, is_edge);
+ if (r > 0)
+ /* We are executing the operation, so make sure we don't
+ * execute another one until the lid is opened/closed again */
+ b->lid_close_queued = false;