- if (handle == HANDLE_NO)
- return 0;
-
- if (handle != HANDLE_ALWAYS) {
-
- if (hashmap_size(b->manager->sessions) > 0) {
- log_error("Refusing power-off, user is logged in.");
- warn_melody();
- return -EPERM;
- }
-
- if (manager_is_inhibited(b->manager, INHIBIT_SHUTDOWN, INHIBIT_BLOCK, NULL)) {
- log_error("Refusing power-off, shutdown is inhibited.");
- warn_melody();
- return -EPERM;
- }
- }
-
- log_info("Powering off...");
-
- dbus_error_init(&error);
- r = bus_manager_shutdown_or_sleep_now_or_later(b->manager, SPECIAL_POWEROFF_TARGET, INHIBIT_SHUTDOWN, &error);
- if (r < 0) {
- log_error("Failed to power off: %s", bus_error_message(&error));
- dbus_error_free(&error);
- }
-
- return r;
-}
-
-static int button_suspend(Button *b, HandleButton handle) {
- DBusError error;
- int r;
-
- assert(b);
-
- if (handle == HANDLE_NO)
- return 0;
-
- if (handle != HANDLE_ALWAYS) {
-
- if (hashmap_size(b->manager->sessions) > 0) {
- log_error("Refusing suspend, user is logged in.");
- warn_melody();
- return -EPERM;
- }
-
- if (manager_is_inhibited(b->manager, INHIBIT_SLEEP, INHIBIT_BLOCK, NULL)) {
- log_error("Refusing suspend, sleeping is inhibited.");
- warn_melody();
- return -EPERM;
- }
- }
-
- log_info("Suspending...");
-
- dbus_error_init(&error);
- r = bus_manager_shutdown_or_sleep_now_or_later(b->manager, SPECIAL_SUSPEND_TARGET, INHIBIT_SLEEP, &error);
- if (r < 0) {
- log_error("Failed to suspend: %s", bus_error_message(&error));
- dbus_error_free(&error);
- }
+ 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;