2
* nvidia-settings: A tool for configuring the NVIDIA X driver on Unix
5
* Copyright (C) 2004 NVIDIA Corporation.
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of Version 2 of the GNU General Public
9
* License as published by the Free Software Foundation.
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See Version 2
14
* of the GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the:
19
* Free Software Foundation, Inc.
20
* 59 Temple Place - Suite 330
21
* Boston, MA 02111-1307, USA
26
#include <NvCtrlAttributes.h>
28
#include "display_device_banner.h"
33
#include "ctkdisplaydevice.h"
35
#include "ctkconfig.h"
39
GType ctk_display_device_get_type(void)
41
static GType ctk_display_device_type = 0;
43
if (!ctk_display_device_type) {
44
static const GTypeInfo ctk_display_device_info = {
45
sizeof (CtkDisplayDeviceClass),
47
NULL, /* base_finalize */
48
NULL, /* class_init, */
49
NULL, /* class_finalize */
50
NULL, /* class_data */
51
sizeof (CtkDisplayDevice),
53
NULL, /* instance_init */
56
ctk_display_device_type = g_type_register_static (GTK_TYPE_VBOX,
57
"CtkDisplayDevice", &ctk_display_device_info, 0);
60
return ctk_display_device_type;
64
GtkWidget* ctk_display_device_new(NvCtrlAttributeHandle *handle,
65
CtkConfig *ctk_config, CtkEvent *ctk_event)
68
CtkDisplayDevice *ctk_display_device;
77
guint8 *image_buffer = NULL;
78
const nv_image_t *img;
79
int enabled, i, mask, n;
82
object = g_object_new(CTK_TYPE_DISPLAY_DEVICE, NULL);
84
ctk_display_device = CTK_DISPLAY_DEVICE(object);
85
ctk_display_device->handle = handle;
86
ctk_display_device->ctk_config = ctk_config;
87
ctk_display_device->num_display_devices = 0;
89
gtk_box_set_spacing(GTK_BOX(object), 10);
93
hbox = gtk_hbox_new(FALSE, 0);
94
gtk_box_pack_start(GTK_BOX(object), hbox, FALSE, FALSE, 0);
96
frame = gtk_frame_new(NULL);
97
gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, FALSE, 0);
99
gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
101
img = &display_device_banner_image;
103
image_buffer = decompress_image_data(img);
105
image = gtk_image_new_from_pixbuf
106
(gdk_pixbuf_new_from_data(image_buffer, GDK_COLORSPACE_RGB,
107
FALSE, 8, img->width, img->height,
108
img->width * img->bytes_per_pixel,
109
free_decompressed_image, NULL));
111
gtk_container_add(GTK_CONTAINER(frame), image);
114
* In the future: this page will be where things like TwinView
115
* will be configured. In the meantime, just put place holders
116
* for each display device present on this X screen.
119
ret = NvCtrlGetAttribute(handle, NV_CTRL_ENABLED_DISPLAYS, &enabled);
120
if (ret != NvCtrlSuccess) {
124
ctk_display_device->enabled_display_devices = enabled;
126
/* create an alignment to center the placeholder */
128
alignment = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
129
gtk_box_pack_start(GTK_BOX(object), alignment, TRUE, FALSE, 0);
131
/* create a frame to hold the whole placeholder */
133
frame = gtk_frame_new(NULL);
134
gtk_container_add(GTK_CONTAINER(alignment), frame);
136
/* create an hbox to hold each display device */
138
hbox = gtk_hbox_new(FALSE, 5);
139
gtk_container_add(GTK_CONTAINER(frame), hbox);
141
/* create a vbox with image and label for each display device */
143
for (n = 0, i = 0; i < 24; i++) {
146
if (!(enabled & mask)) continue;
148
/* get the name of the display device */
151
NvCtrlGetStringDisplayAttribute(handle, mask,
152
NV_CTRL_STRING_DISPLAY_DEVICE_NAME,
155
if ((ret != NvCtrlSuccess) || (!name)) {
156
name = g_strdup("Unknown");
159
/* get the correct image for each display device type */
161
if (mask & CTK_DISPLAY_DEVICE_CRT_MASK) {
163
} else if (mask & CTK_DISPLAY_DEVICE_TV_MASK) {
165
} else if (mask & CTK_DISPLAY_DEVICE_DFP_MASK) {
171
vbox = gtk_vbox_new(FALSE, 5);
172
gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 5);
174
frame = gtk_frame_new(NULL);
175
gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
177
image_buffer = decompress_image_data(img);
179
image = gtk_image_new_from_pixbuf
180
(gdk_pixbuf_new_from_data(image_buffer, GDK_COLORSPACE_RGB,
181
TRUE, 8, img->width, img->height,
182
img->width * img->bytes_per_pixel,
183
free_decompressed_image, NULL));
185
gtk_container_add(GTK_CONTAINER(frame), image);
187
label = gtk_label_new(name);
189
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
191
/* save the display device name */
193
ctk_display_device->display_device_names[n] = name;
195
/* increment the display device count */
200
ctk_display_device->num_display_devices = n;
204
gtk_widget_show_all(GTK_WIDGET(object));
206
return GTK_WIDGET(object);
208
} /* ctk_display_device_new() */
213
* ctk_display_device_create_help() - construct help page
216
GtkTextBuffer *ctk_display_device_create_help(GtkTextTagTable *table,
222
char *title, *page, *s, *tmp, *name;
225
num = ctk_display_device->num_display_devices;
228
title = "Display Device Help";
231
title = "Display Devices Help";
235
/* ugliness to build list of display device names */
238
for (n = 0; n < num; n++) {
240
name = ctk_display_device->display_device_names[n];
244
s = g_strconcat(s, " ", NULL);
252
if (n == (num - 1)) {
253
s = g_strconcat(s, name, NULL);
254
} else if (n == (num - 2)) {
255
s = g_strconcat(s, name, " and", NULL);
257
s = g_strconcat(s, name, ",", NULL);
264
b = gtk_text_buffer_new(table);
266
gtk_text_buffer_get_iter_at_offset(b, &i, 0);
268
ctk_help_title(b, &i, title);
270
ctk_help_para(b, &i, "The %s page is a place holder until support "
271
"for configuring TwinView is added.", title);
273
ctk_help_para(b, &i, "Please see the %s for%s for per-display device "
274
"configuration.", page, s);
280
} /* ctk_display_device_create_help() */