1*9c5db199SXin Li /*
2*9c5db199SXin Li * Copyright 2007, Intel Corporation
3*9c5db199SXin Li *
4*9c5db199SXin Li * This file is part of PowerTOP
5*9c5db199SXin Li *
6*9c5db199SXin Li * This program file is free software; you can redistribute it and/or modify it
7*9c5db199SXin Li * under the terms of the GNU General Public License as published by the
8*9c5db199SXin Li * Free Software Foundation; version 2 of the License.
9*9c5db199SXin Li *
10*9c5db199SXin Li * This program is distributed in the hope that it will be useful, but WITHOUT
11*9c5db199SXin Li * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12*9c5db199SXin Li * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13*9c5db199SXin Li * for more details.
14*9c5db199SXin Li *
15*9c5db199SXin Li * You should have received a copy of the GNU General Public License
16*9c5db199SXin Li * along with this program in a file named COPYING; if not, write to the
17*9c5db199SXin Li * Free Software Foundation, Inc.,
18*9c5db199SXin Li * 51 Franklin Street, Fifth Floor,
19*9c5db199SXin Li * Boston, MA 02110-1301 USA
20*9c5db199SXin Li *
21*9c5db199SXin Li * Authors:
22*9c5db199SXin Li * Arjan van de Ven <[email protected]>
23*9c5db199SXin Li */
24*9c5db199SXin Li
25*9c5db199SXin Li #include <unistd.h>
26*9c5db199SXin Li #include <stdio.h>
27*9c5db199SXin Li #include <stdlib.h>
28*9c5db199SXin Li #include <string.h>
29*9c5db199SXin Li #include <stdint.h>
30*9c5db199SXin Li #include <sys/types.h>
31*9c5db199SXin Li #include <dirent.h>
32*9c5db199SXin Li
33*9c5db199SXin Li #include "powertop.h"
34*9c5db199SXin Li
35*9c5db199SXin Li int has_no_xrandr;
36*9c5db199SXin Li
activate_noTV(void)37*9c5db199SXin Li static void activate_noTV(void)
38*9c5db199SXin Li {
39*9c5db199SXin Li system("xrandr --auto &> /dev/null");
40*9c5db199SXin Li system("xrandr --output TV --off &> /dev/null");
41*9c5db199SXin Li }
42*9c5db199SXin Li
suggest_xrandr_TV_off(void)43*9c5db199SXin Li void suggest_xrandr_TV_off(void)
44*9c5db199SXin Li {
45*9c5db199SXin Li FILE *file;
46*9c5db199SXin Li int has_tv = 0;
47*9c5db199SXin Li int has_tv_active = 0;
48*9c5db199SXin Li char line[1024];
49*9c5db199SXin Li
50*9c5db199SXin Li if (has_no_xrandr)
51*9c5db199SXin Li return;
52*9c5db199SXin Li
53*9c5db199SXin Li memset(line, 0, 1024);
54*9c5db199SXin Li file = popen("xrandr 2> /dev/null", "r");
55*9c5db199SXin Li if (!file || feof(file)) {
56*9c5db199SXin Li has_no_xrandr = 1;
57*9c5db199SXin Li return;
58*9c5db199SXin Li }
59*9c5db199SXin Li while (!feof(file)) {
60*9c5db199SXin Li if (fgets(line, 1024, file)==NULL)
61*9c5db199SXin Li break;
62*9c5db199SXin Li if (line[0]!=' ') {
63*9c5db199SXin Li if (line[0]=='T' && line[1]=='V' && line[2]==' ')
64*9c5db199SXin Li has_tv = 1;
65*9c5db199SXin Li else
66*9c5db199SXin Li has_tv = 0;
67*9c5db199SXin Li } else {
68*9c5db199SXin Li if (strchr(line,'*') && has_tv)
69*9c5db199SXin Li has_tv_active = 1;
70*9c5db199SXin Li }
71*9c5db199SXin Li
72*9c5db199SXin Li }
73*9c5db199SXin Li pclose(file);
74*9c5db199SXin Li if (has_tv_active)
75*9c5db199SXin Li add_suggestion(_("Suggestion: disable TV out via: \n"
76*9c5db199SXin Li " xrandr --output TV --off \n"
77*9c5db199SXin Li "or press the V key."),
78*9c5db199SXin Li 35, 'V', _(" V - Disable TV out "), activate_noTV);
79*9c5db199SXin Li /* check this only once if no suggestion needed */
80*9c5db199SXin Li else
81*9c5db199SXin Li has_no_xrandr = 1;
82*9c5db199SXin Li }
83