! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
the time left dialog needs a lock button
Status:
RESOLVED: FIXED
Product:
Xfce4-time-out-plugin
Component:
General

Comments

Description Joshua Cogliati 2019-12-30 16:59:34 CET
Created attachment 9341 
Patch to add lock button to 1.1.0

The time left dialog would be much more useful with a lock button.  During the break if I want to leave the computer, sometimes it would be useful to be able to lock the screen so a password is required to get back on the computer.

The attached patch implements this feature by adding a lock button that will run xflock4 when it is pressed.

Possible things to fix with patch before merging:
1. Put Lock button horizontally with Postpone button instead of vertically.
2. Resume locking screen instead of exiting if xflock4 fails.

Let me know if there is anything you would like me to do to improve this patch.

Thanks.

Joshua Cogliati
Comment 1 Joshua Cogliati 2019-12-30 17:27:02 CET
Hm, this needs more testing.  Sometimes the lock button doesn't work (or needs to be pressed multiple times)
Comment 2 Joshua Cogliati 2019-12-30 19:07:51 CET
Switching to g_spawn_command_line_sync sorta solves the problem.  However, with xscreensaver, it doesn't always start until the mouse is moved (as in, click Lock, then wait a moment, then move the mouse)

Here is the second attempt at the code (with debugging statements left in:

static void
time_out_lock (TimeOutLockScreen *lock_screen,
	       TimeOutPlugin     *time_out)
{
  GError      *error = NULL;
  gboolean     succeed = FALSE;
  gint         exit_status;

  {
    FILE *fp;
    fp = fopen ("/tmp/panel_out", "a+");
    fputs("in time_out_lock\n", fp);
    fclose(fp);
  }

  g_return_if_fail (IS_TIME_OUT_LOCK_SCREEN (lock_screen));
  g_return_if_fail (time_out != NULL);

  /* Unlock the screen so screensaver can show */
  time_out_lock_screen_hide (time_out->lock_screen);

  /* Lock screen and check for errors */
  //succeed = g_spawn_command_line_async ("xflock4", &error);
  //g_usleep (10*1000);
  succeed = g_spawn_command_line_sync ("xflock4", NULL, NULL, &exit_status , &error);

  {
    FILE *fp;
    fp = fopen ("/tmp/panel_out", "a+");
    fprintf(fp, "exit status %d\n", exit_status);
    if (succeed) {
      fputs("locked screen\n", fp);
    } else {
      fputs("failed to lock screen\n", fp);
    }
    fclose(fp);
  }
  if (!succeed)
  {
    xfce_dialog_show_error (NULL, error,
			    _("Failed to lock screen"));
  } else {
    /* Display the lock screen under screensaver */
    time_out_lock_screen_show (time_out->lock_screen, time_out->lock_countdown_seconds);
  }

}
Comment 3 Joshua Cogliati 2020-01-03 05:18:46 CET
Created attachment 9349 
Patch to add lock button to 1.1.0 with sync

This switches to using sync instead of async to fix a bug. This also puts the button horizontally with the postpone button.
Comment 4 Andre Miranda editbugs 2020-01-05 20:15:58 CET
I like this idea, very handy indeed, however the latest patch doesn't for well for me, I use i3lock-fancy. After locking and unlocking, the countdown dialog is gone but the blocking overlay remains.
Comment 5 Joshua Cogliati 2020-01-06 04:08:34 CET
(In reply to Andre Miranda from comment #4)
> I like this idea, very handy indeed, however the latest patch doesn't for
> well for me, I use i3lock-fancy. After locking and unlocking, the countdown
> dialog is gone but the blocking overlay remains.

Just out of curiosity, what happens if you use "Lock Screen" in the action buttons?  Does that work for you? (or running "xflock4" from the command line?)
Comment 6 Andre Miranda editbugs 2020-01-07 04:20:28 CET
Both work, calling the lock screen (i3lock) from the break screen also works, the problem is because your patch hides the break screen, calls the lock screen and then shows the break screen again, cool, my screen is locked, but when I unlock time-out-plugin is still blocking it with its overlay but no dialog in the center allowing me to lock again or postpone.
Comment 7 Andre Miranda editbugs 2020-01-07 14:36:50 CET
Just for the record, someone told me this problem is already present if the screen is locked while time-out-plugin is blocking it (can't check right now). So it may be another bug, possibly related to the gtk3 port.
Comment 8 Joshua Cogliati 2020-01-08 13:55:48 CET
Hm, maybe the code should always show the time out screen again instead of being in the else branch:

  if (!succeed)
  {
    xfce_dialog_show_error (NULL, error,
			    _("Failed to lock screen"));
  }
   /* Display the lock screen under screensaver */
    time_out_lock_screen_show (time_out->lock_screen, time_out->lock_countdown_seconds);
Comment 9 Joshua Cogliati 2020-01-11 02:13:07 CET
Created attachment 9372 
updated patch to add lock button

This patch moves restarting the dialog out of the else block.  This fixes the minor problem that if xflock4 errors out the timing never gets restarted.
Comment 10 Andre Miranda editbugs 2020-01-11 06:01:42 CET
Even with your latest patch I have the same issue.

Add the functions below and calling them instead time_out_lock_screen_hide/show did the trick for me. Is there any reason to hide the blocking dialog before locking other than allowing the screen locker to grab?

void
time_out_lock_screen_grab (TimeOutLockScreen *lock_screen)
{
  time_out_lock_screen_grab_seat (lock_screen->seat, lock_screen->window);
}

void
time_out_lock_screen_ungrab (TimeOutLockScreen *lock_screen)
{
  gdk_seat_ungrab (lock_screen->seat);
}

Notice that grab won't work because the screen locker holds it, you can add parameters to time_out_lock_screen_grab_seat so it knows it should try to grab indefinitely and with a larger retry interval (i.e. 1 sec).
Comment 11 Joshua Cogliati 2020-01-15 04:39:32 CET
Created attachment 9381 
Patch using grab ungrab

This turns  Andre Miranda comment into a patch.  Thank you for the suggestion.

> Is there any reason to hide the blocking dialog before locking other than allowing the screen locker to grab?

No, that was the reason I hid it.
Comment 12 Joshua Cogliati 2020-01-17 18:18:13 CET
Created attachment 9392 
Patch using grab and ungrab

This patch uses grab seat and ungrab seat as suggested by Andre Miranda.  This patch is functionally the same as the previous version but with better comments and moving the prototypes to the header file.
Comment 13 Joshua Cogliati 2020-01-26 14:30:31 CET
Created attachment 9404 
Patch using grab and ungrab

This patch uses grab and ungrab.  I have tested this method for a week with both xscreensaver and xfce4-screensaver, and it works fine for me.  (I thought it had a problem with sometimes keeping the keyboard, but that was because I had both xsceensaver and xfce4-screensaver running at the same time.)
Comment 14 Git Bot editbugs 2020-02-11 04:33:05 CET
Joshua Cogliati referenced this bugreport in commit f62ea6c46175c32d69ffba51d5f71cfcd3f8f397

Add lock button to break dialog (Bug #16317)

https://git.xfce.org/panel-plugins/xfce4-time-out-plugin/commit?id=f62ea6c46175c32d69ffba51d5f71cfcd3f8f397
Comment 15 Andre Miranda editbugs 2020-02-11 04:38:16 CET
Hi Joshua, thanks for the last patch, it works nicely for me, great job!
I have made a few changes to it though:
- Formatting (only spaces instead of tabs)
- Make postpone and lock buttons fill the horizontal space
- Hide lock button when break time is over
- Made you the commit author (hope you don't mind)

I did a release of this plugin not long ago (3 months) so I going to wait a bit more, if you have more improvements underway please let me know. If not and I forgot to release it, please ping me at #xfce-dev.
Comment 16 Joshua Cogliati 2020-02-11 05:07:45 CET
Thank you for applying the patch.  I don't have any more improvements underway.

(In reply to Andre Miranda from comment #15)

Bug #16317

Reported by:
Joshua Cogliati
Reported on: 2019-12-30
Last modified on: 2020-02-11

People

Assignee:
Xfce-Goodies Maintainers
CC List:
2 users

Version

Attachments

Patch to add lock button to 1.1.0 (5.76 KB, patch)
2019-12-30 16:59 CET , Joshua Cogliati
no flags
Patch to add lock button to 1.1.0 with sync (6.80 KB, patch)
2020-01-03 05:18 CET , Joshua Cogliati
no flags
updated patch to add lock button (6.79 KB, patch)
2020-01-11 02:13 CET , Joshua Cogliati
no flags
Patch using grab ungrab (7.15 KB, patch)
2020-01-15 04:39 CET , Joshua Cogliati
no flags
Patch using grab and ungrab (7.92 KB, patch)
2020-01-17 18:18 CET , Joshua Cogliati
no flags
Patch using grab and ungrab (7.92 KB, patch)
2020-01-26 14:30 CET , Joshua Cogliati
no flags

Additional information