1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2008 RĂ©mi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
25 #include <vlc_common.h>
26 #include <vlc_plugin.h>
27 #include <vlc_inhibit.h>
33 static int Open (vlc_object_t *);
34 static void Close (vlc_object_t *);
37 set_shortname (N_("XDG-screensaver") )
38 set_description (N_("XDG screen saver inhibition") )
39 set_capability ("inhibit", 10 )
40 set_callbacks (Open, Close)
41 set_category (CAT_ADVANCED)
42 set_subcategory (SUBCAT_ADVANCED_MISC)
45 struct vlc_inhibit_sys
48 posix_spawnattr_t attr;
51 extern char **environ;
53 static void Timer (void *data)
55 vlc_inhibit_t *ih = data;
56 vlc_inhibit_sys_t *sys = ih->p_sys;
58 (char *)"xdg-screensaver", (char *)"reset", NULL
62 int err = posix_spawnp (&pid, "xdg-screensaver", NULL, &sys->attr,
68 while (waitpid (pid, &status, 0) == -1);
71 msg_Warn (ih, "error starting xdg-screensaver: %s",
75 static void Inhibit (vlc_inhibit_t *ih, unsigned mask)
77 vlc_inhibit_sys_t *sys = ih->p_sys;
78 bool suspend = (mask & VLC_INHIBIT_DISPLAY) != 0;
79 mtime_t delay = suspend ? 30 * CLOCK_FREQ : INT64_C(0);
81 vlc_timer_schedule (sys->timer, false, delay, delay);
84 static int Open (vlc_object_t *obj)
86 vlc_inhibit_t *ih = (vlc_inhibit_t *)obj;
87 vlc_inhibit_sys_t *p_sys = malloc (sizeof (*p_sys));
91 posix_spawnattr_init (&p_sys->attr);
92 /* Reset signal handlers to default and clear mask in the child process */
97 posix_spawnattr_setsigmask (&p_sys->attr, &set);
98 sigaddset (&set, SIGPIPE);
99 posix_spawnattr_setsigdefault (&p_sys->attr, &set);
100 posix_spawnattr_setflags (&p_sys->attr, POSIX_SPAWN_SETSIGDEF
101 | POSIX_SPAWN_SETSIGMASK);
105 if (vlc_timer_create (&p_sys->timer, Timer, ih))
107 posix_spawnattr_destroy (&p_sys->attr);
112 ih->inhibit = Inhibit;
116 static void Close (vlc_object_t *obj)
118 vlc_inhibit_t *ih = (vlc_inhibit_t *)obj;
119 vlc_inhibit_sys_t *p_sys = ih->p_sys;
121 vlc_timer_destroy (p_sys->timer);
122 posix_spawnattr_destroy (&p_sys->attr);