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