]> git.sesse.net Git - vlc/blob - modules/misc/screensaver.c
Improvements to preferences
[vlc] / modules / misc / screensaver.c
1 /*****************************************************************************
2  * screensaver.c : disable screen savers when VLC is playing
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id$
6  *
7  * Authors: Sam Hocevar <sam@zoy.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>
28
29 #include <vlc/vlc.h>
30 #include <vlc/intf.h>
31 #include <vlc/aout.h>
32 #include <vlc/vout.h>
33
34 /*****************************************************************************
35  * Local prototypes
36  *****************************************************************************/
37 static int  Activate     ( vlc_object_t * );
38 static void Run          ( intf_thread_t *p_intf );
39
40 /*****************************************************************************
41  * Module descriptor
42  *****************************************************************************/
43 vlc_module_begin();
44     set_category( CAT_INTERFACE );
45     set_subcategory( SUBCAT_INTERFACE_CONTROL );
46     set_description( _("X Screensaver disabler") );
47     set_capability( "interface", 0 );
48     set_callbacks( Activate, NULL );
49 vlc_module_end();
50
51 /*****************************************************************************
52  * Activate: initialize and create stuff
53  *****************************************************************************/
54 static int Activate( vlc_object_t *p_this )
55 {
56     intf_thread_t *p_intf = (intf_thread_t*)p_this;
57
58     p_intf->pf_run = Run;
59
60     return VLC_SUCCESS;
61 }
62
63 /*****************************************************************************
64  * Run: main thread
65  *****************************************************************************
66  * This part of the module is in a separate thread so that we do not have
67  * too much system() overhead.
68  *****************************************************************************/
69 static void Run( intf_thread_t *p_intf )
70 {
71     int i_lastcall = 0;
72
73     while( !p_intf->b_die )
74     {
75         msleep( 100000 );
76
77         /* Check screensaver every 30 seconds */
78         if( ++i_lastcall > 300 )
79         {
80             vlc_object_t *p_vout;
81             p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
82             /* If there is a video output, disable xscreensaver */
83             if( p_vout )
84             {
85                 vlc_object_release( p_vout );
86
87                 /* http://www.jwz.org/xscreensaver/faq.html#dvd */
88                 system( "xscreensaver-command -deactivate >&- 2>&- &" );
89
90                 /* FIXME: add support for other screensavers */
91             }
92
93             i_lastcall = 0;
94         }
95     }
96 }
97