3 # include <security/pam_appl.h>
7 #define E_DESKLOCK_STATE_DEFAULT 0
8 #define E_DESKLOCK_STATE_CHECKING 1
9 #define E_DESKLOCK_STATE_INVALID 2
11 #define ELOCK_POPUP_LAYER 10000
12 #define PASSWD_LEN 256
14 /**************************** private data ******************************/
15 typedef struct _E_Desklock_Data E_Desklock_Data;
16 typedef struct _E_Desklock_Popup_Data E_Desklock_Popup_Data;
18 typedef struct _E_Desklock_Auth E_Desklock_Auth;
21 struct _E_Desklock_Popup_Data
24 Evas_Object *bg_object;
25 Evas_Object *login_box;
28 struct _E_Desklock_Data
30 Eina_List *elock_wnd_list;
31 Ecore_X_Window elock_wnd;
33 Ecore_X_Window elock_grab_break_wnd;
34 char passwd[PASSWD_LEN];
39 struct _E_Desklock_Auth
48 char passwd[PATH_MAX];
52 static E_Desklock_Data *edd = NULL;
53 static E_Zone *last_active_zone = NULL;
55 static Ecore_Event_Handler *_e_desklock_exit_handler = NULL;
56 static pid_t _e_desklock_child_pid = -1;
58 static Ecore_Exe *_e_custom_desklock_exe = NULL;
59 static Ecore_Event_Handler *_e_custom_desklock_exe_handler = NULL;
60 static Ecore_Poller *_e_desklock_idle_poller = NULL;
61 static int _e_desklock_user_idle = 0;
62 static double _e_desklock_autolock_time = 0.0;
63 static E_Dialog *_e_desklock_ask_presentation_dia = NULL;
64 static int _e_desklock_ask_presentation_count = 0;
66 /***********************************************************************/
68 static Eina_Bool _e_desklock_cb_key_down(void *data, int type, void *event);
69 static Eina_Bool _e_desklock_cb_mouse_move(void *data, int type, void *event);
70 static Eina_Bool _e_desklock_cb_custom_desklock_exit(void *data, int type, void *event);
71 static Eina_Bool _e_desklock_cb_idle_poller(void *data);
72 static Eina_Bool _e_desklock_cb_window_stack(void *data, int type, void *event);
74 static void _e_desklock_null(void);
75 static void _e_desklock_passwd_update(void);
76 static void _e_desklock_backspace(void);
77 static void _e_desklock_delete(void);
78 static int _e_desklock_zone_num_get(void);
79 static int _e_desklock_check_auth(void);
80 static void _e_desklock_state_set(int state);
83 static Eina_Bool _e_desklock_cb_exit(void *data, int type, void *event);
84 static int _desklock_auth(char *passwd);
85 static int _desklock_pam_init(E_Desklock_Auth *da);
86 static int _desklock_auth_pam_conv(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr);
87 static char *_desklock_auth_get_current_user(void);
88 static char *_desklock_auth_get_current_host(void);
91 static void _e_desklock_ask_presentation_mode(void);
93 EAPI int E_EVENT_DESKLOCK = 0;
98 /* A poller to tick every 256 ticks, watching for an idle user */
99 _e_desklock_idle_poller = ecore_poller_add(ECORE_POLLER_CORE, 256,
100 _e_desklock_cb_idle_poller, NULL);
102 if (e_config->desklock_background)
103 e_filereg_register(e_config->desklock_background);
105 E_EVENT_DESKLOCK = ecore_event_type_new();
111 e_desklock_shutdown(void)
115 if (e_config->desklock_background)
116 e_filereg_deregister(e_config->desklock_background);
122 _user_wallpaper_get(void)
124 const E_Config_Desktop_Background *cdbg;
127 if (e_config->desktop_default_background)
128 return e_config->desktop_default_background;
130 EINA_LIST_FOREACH(e_config->desktop_backgrounds, l, cdbg)
131 if (cdbg->file) return cdbg->file;
133 return e_theme_edje_file_get("base/theme/desklock", "e/desklock/background");
137 e_desklock_show_autolocked(void)
139 if (e_util_fullscreen_curreny_any()) return 0;
140 if (_e_desklock_autolock_time < 1.0)
141 _e_desklock_autolock_time = ecore_loop_time_get();
142 return e_desklock_show();
146 e_desklock_show(void)
148 Eina_List *managers, *l, *l2, *l3;
150 E_Desklock_Popup_Data *edp;
152 E_Zone *current_zone;
153 int zone_counter, total_zone_num;
154 E_Event_Desklock *ev;
156 if (_e_custom_desklock_exe) return 0;
158 if (e_config->desklock_use_custom_desklock)
160 _e_custom_desklock_exe_handler =
161 ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
162 _e_desklock_cb_custom_desklock_exit, NULL);
163 e_util_library_path_strip();
164 _e_custom_desklock_exe =
165 ecore_exe_run(e_config->desklock_custom_desklock_cmd, NULL);
166 e_util_library_path_restore();
171 e_util_dialog_show(_("Error - no PAM support"),
172 _("No PAM support was built into Enlightenment, so<br>"
173 "desk locking is disabled."));
180 if (e_config->desklock_auth_method == 1)
183 if (!e_config->desklock_personal_passwd)
187 zone = e_util_zone_current_get(e_manager_current_get());
189 e_configure_registry_call("screen/screen_lock", zone->container, NULL);
196 edd = E_NEW(E_Desklock_Data, 1);
199 ecore_x_window_input_new(e_manager_current_get()->root, 0, 0, 1, 1);
200 ecore_x_window_show(edd->elock_wnd);
201 managers = e_manager_list();
202 if (!e_grabinput_get(edd->elock_wnd, 0, edd->elock_wnd))
204 EINA_LIST_FOREACH(managers, l, man)
206 Ecore_X_Window *windows;
209 windows = ecore_x_window_children_get(man->root, &wnum);
214 for (i = 0; i < wnum; i++)
216 Ecore_X_Window_Attributes att;
218 memset(&att, 0, sizeof(Ecore_X_Window_Attributes));
219 ecore_x_window_attributes_get(windows[i], &att);
222 ecore_x_window_hide(windows[i]);
223 if (e_grabinput_get(edd->elock_wnd, 0, edd->elock_wnd))
225 edd->elock_grab_break_wnd = windows[i];
229 ecore_x_window_show(windows[i]);
235 /* everything failed - can't lock */
236 e_util_dialog_show(_("Lock Failed"),
237 _("Locking the desktop failed because some application<br>"
238 "has grabbed either the keyboard or the mouse or both<br>"
239 "and their grab is unable to be broken."));
240 ecore_x_window_free(edd->elock_wnd);
246 last_active_zone = current_zone =
247 e_zone_current_get(e_container_current_get(e_manager_current_get()));
250 total_zone_num = _e_desklock_zone_num_get();
251 EINA_LIST_FOREACH(managers, l, man)
255 EINA_LIST_FOREACH(man->containers, l2, con)
259 EINA_LIST_FOREACH(con->zones, l3, zone)
261 edp = E_NEW(E_Desklock_Popup_Data, 1);
264 edp->popup_wnd = e_popup_new(zone, 0, 0, zone->w, zone->h);
265 evas_event_feed_mouse_move(edp->popup_wnd->evas, -1000000, -1000000,
266 ecore_x_current_time_get(), NULL);
268 e_popup_layer_set(edp->popup_wnd, ELOCK_POPUP_LAYER);
269 ecore_evas_raise(edp->popup_wnd->ecore_evas);
271 evas_event_freeze(edp->popup_wnd->evas);
272 edp->bg_object = edje_object_add(edp->popup_wnd->evas);
274 if ((!e_config->desklock_background) ||
275 (!strcmp(e_config->desklock_background, "theme_desklock_background")))
277 e_theme_edje_object_set(edp->bg_object,
278 "base/theme/desklock",
279 "e/desklock/background");
281 else if (!strcmp(e_config->desklock_background, "theme_background"))
283 e_theme_edje_object_set(edp->bg_object,
284 "base/theme/backgrounds",
285 "e/desktop/background");
291 if (!strcmp(e_config->desklock_background, "user_background"))
292 f = _user_wallpaper_get();
294 f = e_config->desklock_background;
296 if (e_util_edje_collection_exists(f, "e/desklock/background"))
298 edje_object_file_set(edp->bg_object, f,
299 "e/desklock/background");
303 if (!edje_object_file_set(edp->bg_object,
304 f, "e/desktop/background"))
306 edje_object_file_set(edp->bg_object,
307 e_theme_edje_file_get("base/theme/desklock",
308 "e/desklock/background"),
309 "e/desklock/background");
314 evas_object_move(edp->bg_object, 0, 0);
315 evas_object_resize(edp->bg_object, zone->w, zone->h);
316 evas_object_show(edp->bg_object);
317 edp->login_box = edje_object_add(edp->popup_wnd->evas);
318 e_theme_edje_object_set(edp->login_box,
319 "base/theme/desklock",
320 "e/desklock/login_box");
321 edje_object_part_text_set(edp->login_box, "e.text.title",
322 _("Please enter your unlock password"));
323 edje_object_size_min_calc(edp->login_box, &mw, &mh);
324 if (edje_object_part_exists(edp->bg_object, "e.swallow.login_box"))
326 edje_extern_object_min_size_set(edp->login_box, mw, mh);
327 edje_object_part_swallow(edp->bg_object, "e.swallow.login_box", edp->login_box);
331 evas_object_resize(edp->login_box, mw, mh);
332 evas_object_move(edp->login_box,
333 ((zone->w - mw) / 2),
334 ((zone->h - mh) / 2));
336 if (total_zone_num > 1)
338 if (e_config->desklock_login_box_zone == -1)
339 evas_object_show(edp->login_box);
340 else if ((e_config->desklock_login_box_zone == -2) &&
341 (zone == current_zone))
342 evas_object_show(edp->login_box);
343 else if (e_config->desklock_login_box_zone == zone_counter)
344 evas_object_show(edp->login_box);
347 evas_object_show(edp->login_box);
349 e_popup_edje_bg_object_set(edp->popup_wnd, edp->bg_object);
350 evas_event_thaw(edp->popup_wnd->evas);
352 e_popup_show(edp->popup_wnd);
354 edd->elock_wnd_list = eina_list_append(edd->elock_wnd_list, edp);
363 eina_list_append(edd->handlers,
364 ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
365 _e_desklock_cb_key_down, NULL));
367 eina_list_append(edd->handlers,
368 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_STACK,
369 _e_desklock_cb_window_stack, NULL));
371 eina_list_append(edd->handlers,
372 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_CONFIGURE,
373 _e_desklock_cb_window_stack, NULL));
375 eina_list_append(edd->handlers,
376 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_CREATE,
377 _e_desklock_cb_window_stack, NULL));
379 if ((total_zone_num > 1) && (e_config->desklock_login_box_zone == -2))
382 eina_list_append(edd->handlers,
383 ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE,
384 _e_desklock_cb_mouse_move,
388 _e_desklock_passwd_update();
390 ev = E_NEW(E_Event_Desklock, 1);
392 ecore_event_add(E_EVENT_DESKLOCK, ev, NULL, NULL);
397 e_desklock_hide(void)
399 E_Desklock_Popup_Data *edp;
400 E_Event_Desklock *ev;
402 if ((!edd) && (!_e_custom_desklock_exe)) return;
404 if (e_config->desklock_use_custom_desklock)
406 _e_custom_desklock_exe = NULL;
410 if (edd->elock_grab_break_wnd)
411 ecore_x_window_show(edd->elock_grab_break_wnd);
413 EINA_LIST_FREE(edd->elock_wnd_list, edp)
417 e_popup_hide(edp->popup_wnd);
419 evas_event_freeze(edp->popup_wnd->evas);
420 evas_object_del(edp->bg_object);
421 evas_object_del(edp->login_box);
422 evas_event_thaw(edp->popup_wnd->evas);
424 e_util_defer_object_del(E_OBJECT(edp->popup_wnd));
429 E_FREE_LIST(edd->handlers, ecore_event_handler_del);
431 e_grabinput_release(edd->elock_wnd, edd->elock_wnd);
432 ecore_x_window_free(edd->elock_wnd);
437 ev = E_NEW(E_Event_Desklock, 1);
439 ecore_event_add(E_EVENT_DESKLOCK, ev, NULL, NULL);
441 if (_e_desklock_autolock_time > 0.0)
443 if ((e_config->desklock_ask_presentation) &&
444 (e_config->desklock_ask_presentation_timeout > 0.0))
448 now = ecore_loop_time_get();
449 max = _e_desklock_autolock_time + e_config->desklock_ask_presentation_timeout;
451 _e_desklock_ask_presentation_mode();
454 _e_desklock_ask_presentation_count = 0;
456 _e_desklock_autolock_time = 0.0;
461 _e_desklock_cb_window_stack(void *data __UNUSED__,
466 E_Desklock_Popup_Data *edp;
468 Eina_Bool raise = EINA_TRUE;
470 if (type == ECORE_X_EVENT_WINDOW_STACK)
471 win = ((Ecore_X_Event_Window_Stack*) event)->event_win;
472 else if (type == ECORE_X_EVENT_WINDOW_STACK)
473 win = ((Ecore_X_Event_Window_Configure*) event)->event_win;
474 else if (type == ECORE_X_EVENT_WINDOW_CREATE)
475 win = ((Ecore_X_Event_Window_Create*) event)->win;
477 return ECORE_CALLBACK_PASS_ON;
479 EINA_LIST_FOREACH(edd->elock_wnd_list, l, edp)
481 if (win == edp->popup_wnd->evas_win)
490 EINA_LIST_FOREACH(edd->elock_wnd_list, l, edp)
491 ecore_evas_raise(edp->popup_wnd->ecore_evas);
494 return ECORE_CALLBACK_PASS_ON;
498 _e_desklock_cb_key_down(void *data __UNUSED__, int type __UNUSED__, void *event)
500 Ecore_Event_Key *ev = event;
502 if ((ev->window != edd->elock_wnd) ||
503 (edd->state == E_DESKLOCK_STATE_CHECKING)) return 1;
505 if (!strcmp(ev->key, "Escape"))
507 else if (!strcmp(ev->key, "KP_Enter"))
508 _e_desklock_check_auth();
509 else if (!strcmp(ev->key, "Return"))
510 _e_desklock_check_auth();
511 else if (!strcmp(ev->key, "BackSpace"))
512 _e_desklock_backspace();
513 else if (!strcmp(ev->key, "Delete"))
514 _e_desklock_delete();
515 else if ((!strcmp(ev->key, "u") &&
516 (ev->modifiers & ECORE_EVENT_MODIFIER_CTRL)))
520 /* here we have to grab a password */
523 if ((strlen(edd->passwd) < (PASSWD_LEN - strlen(ev->compose))))
525 strcat(edd->passwd, ev->compose);
526 _e_desklock_passwd_update();
531 return ECORE_CALLBACK_PASS_ON;
535 _e_desklock_cb_mouse_move(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
537 E_Desklock_Popup_Data *edp;
538 E_Zone *current_zone;
541 current_zone = e_zone_current_get(e_container_current_get(e_manager_current_get()));
543 if (current_zone == last_active_zone)
544 return ECORE_CALLBACK_PASS_ON;
546 EINA_LIST_FOREACH(edd->elock_wnd_list, l, edp)
550 if (edp->popup_wnd->zone == last_active_zone)
551 evas_object_hide(edp->login_box);
552 else if (edp->popup_wnd->zone == current_zone)
553 evas_object_show(edp->login_box);
555 last_active_zone = current_zone;
556 return ECORE_CALLBACK_PASS_ON;
560 _e_desklock_passwd_update(void)
563 char passwd_hidden[PASSWD_LEN] = "", *pp;
564 E_Desklock_Popup_Data *edp;
569 len = eina_unicode_utf8_get_len(edd->passwd);
570 for (i = 0, pp = passwd_hidden ; i < len ; i++, pp++)
574 EINA_LIST_FOREACH(edd->elock_wnd_list, l, edp)
575 edje_object_part_text_set(edp->login_box, "e.text.password",
580 _e_desklock_null(void)
582 memset(edd->passwd, 0, sizeof(char) * PASSWD_LEN);
583 _e_desklock_passwd_update();
587 _e_desklock_backspace(void)
593 len = strlen(edd->passwd);
596 pos = evas_string_char_prev_get(edd->passwd, len, &val);
597 if ((pos < len) && (pos >= 0))
599 edd->passwd[pos] = 0;
600 _e_desklock_passwd_update();
606 _e_desklock_delete(void)
608 _e_desklock_backspace();
612 _e_desklock_zone_num_get(void)
619 EINA_LIST_FOREACH(e_manager_list(), l, man)
622 EINA_LIST_FOREACH(man->containers, l2, con)
623 num += eina_list_count(con->zones);
630 _e_desklock_check_auth(void)
634 if (e_config->desklock_auth_method == 0)
635 return _desklock_auth(edd->passwd);
636 else if (e_config->desklock_auth_method == 1)
639 if ((e_config->desklock_personal_passwd) &&
640 (!strcmp(!edd->passwd ? "" : edd->passwd,
641 !e_config->desklock_personal_passwd ? "" :
642 e_config->desklock_personal_passwd)))
645 /* security - null out passwd string once we are done with it */
646 memset(edd->passwd, 0, sizeof(char) * PASSWD_LEN);
653 /* password is definitely wrong */
654 _e_desklock_state_set(E_DESKLOCK_STATE_INVALID);
660 _e_desklock_state_set(int state)
663 E_Desklock_Popup_Data *edp;
664 const char *signal, *text;
668 if (state == E_DESKLOCK_STATE_CHECKING)
670 signal = "e,state,checking";
671 text = "Authenticating...";
673 else if (state == E_DESKLOCK_STATE_INVALID)
675 signal = "e,state,invalid";
676 text = "The password you entered is invalid. Try again.";
681 EINA_LIST_FOREACH(edd->elock_wnd_list, l, edp)
683 edje_object_signal_emit(edp->login_box, signal, "e.desklock");
684 edje_object_signal_emit(edp->bg_object, signal, "e.desklock");
685 edje_object_part_text_set(edp->login_box, "e.text.title", text);
692 _e_desklock_cb_exit(void *data __UNUSED__, int type __UNUSED__, void *event)
694 Ecore_Exe_Event_Del *ev = event;
696 if (ev->pid == _e_desklock_child_pid)
698 _e_desklock_child_pid = -1;
700 if (ev->exit_code == 0)
702 /* security - null out passwd string once we are done with it */
703 memset(edd->passwd, 0, sizeof(char) * PASSWD_LEN);
707 else if (ev->exit_code < 128)
709 /* security - null out passwd string once we are done with it */
710 memset(edd->passwd, 0, sizeof(char) * PASSWD_LEN);
712 e_util_dialog_show(_("Authentication System Error"),
713 _("Authentication via PAM had errors setting up the<br>"
714 "authentication session. The error code was <hilight>%i</hilight>.<br>"
715 "This is bad and should not be happening. Please report this bug.")
721 _e_desklock_state_set(E_DESKLOCK_STATE_INVALID);
722 /* security - null out passwd string once we are done with it */
725 if (_e_desklock_exit_handler)
726 ecore_event_handler_del(_e_desklock_exit_handler);
727 _e_desklock_exit_handler = NULL;
729 return ECORE_CALLBACK_PASS_ON;
733 _desklock_auth(char *passwd)
735 _e_desklock_state_set(E_DESKLOCK_STATE_CHECKING);
736 _e_desklock_child_pid = fork();
737 if (_e_desklock_child_pid > 0)
740 _e_desklock_exit_handler =
741 ecore_event_handler_add(ECORE_EXE_EVENT_DEL, _e_desklock_cb_exit,
744 else if (_e_desklock_child_pid == 0)
749 char *current_user, *p;
750 struct sigaction action;
752 action.sa_handler = SIG_DFL;
753 action.sa_flags = SA_ONSTACK | SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
754 sigemptyset(&action.sa_mask);
755 sigaction(SIGSEGV, &action, NULL);
756 sigaction(SIGILL, &action, NULL);
757 sigaction(SIGFPE, &action, NULL);
758 sigaction(SIGBUS, &action, NULL);
759 sigaction(SIGABRT, &action, NULL);
761 current_user = _desklock_auth_get_current_user();
762 eina_strlcpy(da.user, current_user, sizeof(da.user));
763 eina_strlcpy(da.passwd, passwd, sizeof(da.passwd));
764 /* security - null out passwd string once we are done with it */
765 for (p = passwd; *p; p++) *p = 0;
766 da.pam.handle = NULL;
767 da.pam.conv.conv = NULL;
768 da.pam.conv.appdata_ptr = NULL;
770 pamerr = _desklock_pam_init(&da);
771 if (pamerr != PAM_SUCCESS)
776 pamerr = pam_authenticate(da.pam.handle, 0);
777 pam_end(da.pam.handle, pamerr);
778 /* security - null out passwd string once we are done with it */
779 memset(da.passwd, 0, sizeof(da.passwd));
780 if (pamerr == PAM_SUCCESS)
790 _e_desklock_state_set(E_DESKLOCK_STATE_INVALID);
797 _desklock_auth_get_current_user(void)
800 struct passwd *pwent = NULL;
802 pwent = getpwuid(getuid());
803 user = strdup(pwent->pw_name);
808 _desklock_pam_init(E_Desklock_Auth *da)
811 const char *pam_prof;
817 da->pam.conv.conv = _desklock_auth_pam_conv;
818 da->pam.conv.appdata_ptr = da;
819 da->pam.handle = NULL;
821 /* try other pam profiles - and system-auth (login for fbsd users) is a fallback */
823 if (ecore_file_exists("/etc/pam.d/enlightenment"))
824 pam_prof = "enlightenment";
825 else if (ecore_file_exists("/etc/pam.d/xscreensaver"))
826 pam_prof = "xscreensaver";
827 else if (ecore_file_exists("/etc/pam.d/kscreensaver"))
828 pam_prof = "kscreensaver";
829 else if (ecore_file_exists("/etc/pam.d/system-auth"))
830 pam_prof = "system-auth";
831 else if (ecore_file_exists("/etc/pam.d/system"))
833 else if (ecore_file_exists("/etc/pam.d/xdm"))
835 else if (ecore_file_exists("/etc/pam.d/gdm"))
837 else if (ecore_file_exists("/etc/pam.d/kdm"))
840 if ((pamerr = pam_start(pam_prof, da->user, &(da->pam.conv),
841 &(da->pam.handle))) != PAM_SUCCESS)
844 current_user = _desklock_auth_get_current_user();
846 if ((pamerr = pam_set_item(da->pam.handle, PAM_USER, current_user)) != PAM_SUCCESS)
852 current_host = _desklock_auth_get_current_host();
853 if ((pamerr = pam_set_item(da->pam.handle, PAM_RHOST, current_host)) != PAM_SUCCESS)
866 _desklock_auth_pam_conv(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr)
869 E_Desklock_Auth *da = (E_Desklock_Auth *)appdata_ptr;
870 struct pam_response *reply = NULL;
872 reply = (struct pam_response *)malloc(sizeof(struct pam_response) *num_msg);
874 if (!reply) return PAM_CONV_ERR;
876 for (replies = 0; replies < num_msg; replies++)
878 switch (msg[replies]->msg_style)
880 case PAM_PROMPT_ECHO_ON:
881 reply[replies].resp_retcode = PAM_SUCCESS;
882 reply[replies].resp = strdup(da->user);
884 case PAM_PROMPT_ECHO_OFF:
885 reply[replies].resp_retcode = PAM_SUCCESS;
886 reply[replies].resp = strdup(da->passwd);
890 reply[replies].resp_retcode = PAM_SUCCESS;
891 reply[replies].resp = NULL;
903 _desklock_auth_get_current_host(void)
905 return strdup("localhost");
910 _e_desklock_cb_custom_desklock_exit(void *data __UNUSED__, int type __UNUSED__, void *event)
912 Ecore_Exe_Event_Del *ev = event;
914 if (ev->exe != _e_custom_desklock_exe) return ECORE_CALLBACK_PASS_ON;
916 if (ev->exit_code != 0)
918 /* do something profound here... like notify someone */
923 return ECORE_CALLBACK_DONE;
927 _e_desklock_cb_idle_poller(void *data __UNUSED__)
929 if ((e_config->desklock_autolock_idle) && (!e_config->mode.presentation) &&
930 (!e_util_fullscreen_curreny_any()))
934 /* If a desklock is already up, bail */
935 if ((_e_custom_desklock_exe) || (edd)) return ECORE_CALLBACK_RENEW;
937 idle = ecore_x_screensaver_idle_time_get();
938 max = e_config->desklock_autolock_idle_timeout;
939 if (_e_desklock_ask_presentation_count > 0)
940 max *= (1 + _e_desklock_ask_presentation_count);
942 /* If we have exceeded our idle time... */
946 * Unfortunately, not all "desklocks" stay up for as long as
947 * the user is idle or until it is unlocked.
949 * 'xscreensaver-command -lock' for example sends a command
950 * to xscreensaver and then terminates. So, we have another
951 * check (_e_desklock_user_idle) which lets us know that we
952 * have locked the screen due to idleness.
954 if (!_e_desklock_user_idle)
956 _e_desklock_user_idle = 1;
957 e_desklock_show_autolocked();
961 _e_desklock_user_idle = 0;
964 /* Make sure our poller persists. */
965 return ECORE_CALLBACK_RENEW;
969 _e_desklock_ask_presentation_del(void *data)
971 if (_e_desklock_ask_presentation_dia == data)
972 _e_desklock_ask_presentation_dia = NULL;
976 _e_desklock_ask_presentation_yes(void *data __UNUSED__, E_Dialog *dia)
978 e_config->mode.presentation = 1;
979 e_config_mode_changed();
980 e_config_save_queue();
981 e_object_del(E_OBJECT(dia));
982 _e_desklock_ask_presentation_count = 0;
986 _e_desklock_ask_presentation_no(void *data __UNUSED__, E_Dialog *dia)
988 e_object_del(E_OBJECT(dia));
989 _e_desklock_ask_presentation_count = 0;
993 _e_desklock_ask_presentation_no_increase(void *data __UNUSED__, E_Dialog *dia)
995 int timeout, interval, blanking, expose;
997 _e_desklock_ask_presentation_count++;
998 timeout = e_config->screensaver_timeout * _e_desklock_ask_presentation_count;
999 interval = e_config->screensaver_interval;
1000 blanking = e_config->screensaver_blanking;
1001 expose = e_config->screensaver_expose;
1003 ecore_x_screensaver_set(timeout, interval, blanking, expose);
1004 e_object_del(E_OBJECT(dia));
1008 _e_desklock_ask_presentation_no_forever(void *data __UNUSED__, E_Dialog *dia)
1010 e_config->desklock_ask_presentation = 0;
1011 e_config_save_queue();
1012 e_object_del(E_OBJECT(dia));
1013 _e_desklock_ask_presentation_count = 0;
1017 _e_desklock_ask_presentation_key_down(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event)
1019 Evas_Event_Key_Down *ev = event;
1020 E_Dialog *dia = data;
1022 if (strcmp(ev->keyname, "Return") == 0)
1023 _e_desklock_ask_presentation_yes(NULL, dia);
1024 else if (strcmp(ev->keyname, "Escape") == 0)
1025 _e_desklock_ask_presentation_no(NULL, dia);
1029 _e_desklock_ask_presentation_mode(void)
1035 if (_e_desklock_ask_presentation_dia) return;
1037 if (!(man = e_manager_current_get())) return;
1038 if (!(con = e_container_current_get(man))) return;
1039 if (!(dia = e_dialog_new(con, "E", "_desklock_ask_presentation"))) return;
1041 e_dialog_title_set(dia, _("Activate Presentation Mode?"));
1042 e_dialog_icon_set(dia, "dialog-ask", 64);
1043 e_dialog_text_set(dia,
1044 _("You unlocked desktop too fast.<br><br>"
1045 "Would you like to enable <b>presentation</b> mode and "
1046 "temporarily disable screen saver, lock and power saving?"));
1048 e_object_del_attach_func_set(E_OBJECT(dia),
1049 _e_desklock_ask_presentation_del);
1050 e_dialog_button_add(dia, _("Yes"), NULL,
1051 _e_desklock_ask_presentation_yes, NULL);
1052 e_dialog_button_add(dia, _("No"), NULL,
1053 _e_desklock_ask_presentation_no, NULL);
1054 e_dialog_button_add(dia, _("No, but increase timeout"), NULL,
1055 _e_desklock_ask_presentation_no_increase, NULL);
1056 e_dialog_button_add(dia, _("No, and stop asking"), NULL,
1057 _e_desklock_ask_presentation_no_forever, NULL);
1059 e_dialog_button_focus_num(dia, 0);
1060 e_widget_list_homogeneous_set(dia->box_object, 0);
1061 e_win_centered_set(dia->win, 1);
1064 evas_object_event_callback_add(dia->bg_object, EVAS_CALLBACK_KEY_DOWN,
1065 _e_desklock_ask_presentation_key_down, dia);
1067 _e_desklock_ask_presentation_dia = dia;