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>
34 static int Open (vlc_object_t *);
35 static void Close (vlc_object_t *);
38 set_shortname (N_("XDG-screensaver") )
39 set_description (N_("XDG screen saver inhibition") )
40 set_capability ("inhibit", 10 )
41 set_callbacks (Open, Close)
42 set_category (CAT_ADVANCED)
43 set_subcategory (SUBCAT_ADVANCED_MISC)
46 struct vlc_inhibit_sys
49 posix_spawnattr_t attr;
52 extern char **environ;
54 static void Timer (void *data)
56 vlc_inhibit_t *ih = data;
57 vlc_inhibit_sys_t *sys = ih->p_sys;
59 (char *)"xdg-screensaver", (char *)"reset", NULL
63 int err = posix_spawnp (&pid, "xdg-screensaver", NULL, &sys->attr,
69 while (waitpid (pid, &status, 0) == -1);
74 msg_Warn (ih, "error starting xdg-screensaver: %m");
78 static void Inhibit (vlc_inhibit_t *ih, unsigned mask)
80 vlc_inhibit_sys_t *sys = ih->p_sys;
81 bool suspend = (mask & VLC_INHIBIT_DISPLAY) != 0;
82 mtime_t delay = suspend ? 30 * CLOCK_FREQ : INT64_C(0);
84 vlc_timer_schedule (sys->timer, false, delay, delay);
87 static int Open (vlc_object_t *obj)
89 vlc_inhibit_t *ih = (vlc_inhibit_t *)obj;
90 vlc_inhibit_sys_t *p_sys = malloc (sizeof (*p_sys));
94 posix_spawnattr_init (&p_sys->attr);
95 /* Reset signal handlers to default and clear mask in the child process */
100 posix_spawnattr_setsigmask (&p_sys->attr, &set);
101 sigaddset (&set, SIGPIPE);
102 posix_spawnattr_setsigdefault (&p_sys->attr, &set);
103 posix_spawnattr_setflags (&p_sys->attr, POSIX_SPAWN_SETSIGDEF
104 | POSIX_SPAWN_SETSIGMASK);
108 if (vlc_timer_create (&p_sys->timer, Timer, ih))
110 posix_spawnattr_destroy (&p_sys->attr);
115 ih->inhibit = Inhibit;
119 static void Close (vlc_object_t *obj)
121 vlc_inhibit_t *ih = (vlc_inhibit_t *)obj;
122 vlc_inhibit_sys_t *p_sys = ih->p_sys;
124 vlc_timer_destroy (p_sys->timer);
125 posix_spawnattr_destroy (&p_sys->attr);