~ubuntu-branches/ubuntu/precise/nvidia-settings/precise-proposed

« back to all changes in this revision

Viewing changes to nvidia-settings-1.0/src/gtk+-2.x/ctkdisplaydevice.c

  • Committer: Bazaar Package Importer
  • Author(s): Randall Donald
  • Date: 2004-07-03 19:09:17 UTC
  • Revision ID: james.westby@ubuntu.com-20040703190917-rqkze2s58ux5pamy
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * nvidia-settings: A tool for configuring the NVIDIA X driver on Unix
 
3
 * and Linux systems.
 
4
 *
 
5
 * Copyright (C) 2004 NVIDIA Corporation.
 
6
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the:
 
18
 *
 
19
 *           Free Software Foundation, Inc.
 
20
 *           59 Temple Place - Suite 330
 
21
 *           Boston, MA 02111-1307, USA
 
22
 *
 
23
 */
 
24
 
 
25
#include <gtk/gtk.h>
 
26
#include <NvCtrlAttributes.h>
 
27
 
 
28
#include "display_device_banner.h"
 
29
#include "crt.h"
 
30
#include "dfp.h"
 
31
#include "tv.h"
 
32
 
 
33
#include "ctkdisplaydevice.h"
 
34
 
 
35
#include "ctkconfig.h"
 
36
#include "ctkhelp.h"
 
37
 
 
38
 
 
39
GType ctk_display_device_get_type(void)
 
40
{
 
41
    static GType ctk_display_device_type = 0;
 
42
    
 
43
    if (!ctk_display_device_type) {
 
44
        static const GTypeInfo ctk_display_device_info = {
 
45
            sizeof (CtkDisplayDeviceClass),
 
46
            NULL, /* base_init */
 
47
            NULL, /* base_finalize */
 
48
            NULL, /* class_init, */
 
49
            NULL, /* class_finalize */
 
50
            NULL, /* class_data */
 
51
            sizeof (CtkDisplayDevice),
 
52
            0, /* n_preallocs */
 
53
            NULL, /* instance_init */
 
54
        };
 
55
 
 
56
        ctk_display_device_type = g_type_register_static (GTK_TYPE_VBOX,
 
57
                "CtkDisplayDevice", &ctk_display_device_info, 0);
 
58
    }
 
59
 
 
60
    return ctk_display_device_type;
 
61
}
 
62
 
 
63
 
 
64
GtkWidget* ctk_display_device_new(NvCtrlAttributeHandle *handle,
 
65
                                  CtkConfig *ctk_config, CtkEvent *ctk_event)
 
66
{
 
67
    GObject *object;
 
68
    CtkDisplayDevice *ctk_display_device;
 
69
    GtkWidget *image;
 
70
    GtkWidget *frame;
 
71
    GtkWidget *hbox;
 
72
    GtkWidget *vbox;
 
73
    GtkWidget *label;
 
74
    GtkWidget *alignment;
 
75
    ReturnStatus ret;
 
76
    
 
77
    guint8 *image_buffer = NULL;
 
78
    const nv_image_t *img;    
 
79
    int enabled, i, mask, n;
 
80
    char *name;
 
81
 
 
82
    object = g_object_new(CTK_TYPE_DISPLAY_DEVICE, NULL);
 
83
 
 
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;
 
88
 
 
89
    gtk_box_set_spacing(GTK_BOX(object), 10);
 
90
    
 
91
    /* banner */
 
92
 
 
93
    hbox = gtk_hbox_new(FALSE, 0);
 
94
    gtk_box_pack_start(GTK_BOX(object), hbox, FALSE, FALSE, 0);
 
95
 
 
96
    frame = gtk_frame_new(NULL);
 
97
    gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, FALSE, 0);
 
98
 
 
99
    gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
 
100
    
 
101
    img = &display_device_banner_image;
 
102
    
 
103
    image_buffer = decompress_image_data(img);
 
104
    
 
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));
 
110
 
 
111
    gtk_container_add(GTK_CONTAINER(frame), image);
 
112
 
 
113
    /*
 
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.
 
117
     */
 
118
    
 
119
    ret = NvCtrlGetAttribute(handle, NV_CTRL_ENABLED_DISPLAYS, &enabled);
 
120
    if (ret != NvCtrlSuccess) {
 
121
        return NULL;
 
122
    }
 
123
    
 
124
    ctk_display_device->enabled_display_devices = enabled;
 
125
    
 
126
    /* create an alignment to center the placeholder */
 
127
    
 
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);
 
130
    
 
131
    /* create a frame to hold the whole placeholder */
 
132
    
 
133
    frame = gtk_frame_new(NULL);
 
134
    gtk_container_add(GTK_CONTAINER(alignment), frame);
 
135
    
 
136
    /* create an hbox to hold each display device */
 
137
    
 
138
    hbox = gtk_hbox_new(FALSE, 5);
 
139
    gtk_container_add(GTK_CONTAINER(frame), hbox);
 
140
    
 
141
    /* create a vbox with image and label for each display device */
 
142
 
 
143
    for (n = 0, i = 0; i < 24; i++) {
 
144
        
 
145
        mask = 1 << i;
 
146
        if (!(enabled & mask)) continue;
 
147
        
 
148
        /* get the name of the display device */
 
149
        
 
150
        ret =
 
151
            NvCtrlGetStringDisplayAttribute(handle, mask,
 
152
                                            NV_CTRL_STRING_DISPLAY_DEVICE_NAME,
 
153
                                            &name);
 
154
        
 
155
        if ((ret != NvCtrlSuccess) || (!name)) {
 
156
            name = g_strdup("Unknown");
 
157
        }
 
158
        
 
159
        /* get the correct image for each display device type */
 
160
        
 
161
        if (mask & CTK_DISPLAY_DEVICE_CRT_MASK) {
 
162
            img = &crt_image;
 
163
        } else if (mask & CTK_DISPLAY_DEVICE_TV_MASK) {
 
164
            img = &tv_image;
 
165
        } else if (mask & CTK_DISPLAY_DEVICE_DFP_MASK) {
 
166
            img = &dfp_image;
 
167
        } else {
 
168
            continue;
 
169
        }
 
170
        
 
171
        vbox = gtk_vbox_new(FALSE, 5);
 
172
        gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 5);
 
173
        
 
174
        frame = gtk_frame_new(NULL);
 
175
        gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
 
176
        
 
177
        image_buffer = decompress_image_data(img);
 
178
 
 
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));
 
184
        
 
185
        gtk_container_add(GTK_CONTAINER(frame), image);
 
186
        
 
187
        label = gtk_label_new(name);
 
188
        
 
189
        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
 
190
 
 
191
        /* save the display device name */
 
192
 
 
193
        ctk_display_device->display_device_names[n] = name;
 
194
        
 
195
        /* increment the display device count */
 
196
        
 
197
        n++;
 
198
    }
 
199
    
 
200
    ctk_display_device->num_display_devices = n;
 
201
 
 
202
    /* show the page */
 
203
 
 
204
    gtk_widget_show_all(GTK_WIDGET(object));
 
205
 
 
206
    return GTK_WIDGET(object);
 
207
 
 
208
} /* ctk_display_device_new() */
 
209
 
 
210
 
 
211
 
 
212
/*
 
213
 * ctk_display_device_create_help() - construct help page
 
214
 */
 
215
 
 
216
GtkTextBuffer *ctk_display_device_create_help(GtkTextTagTable *table,
 
217
                                              CtkDisplayDevice
 
218
                                              *ctk_display_device)
 
219
{
 
220
    GtkTextIter i;
 
221
    GtkTextBuffer *b;
 
222
    char *title, *page, *s, *tmp, *name;
 
223
    int n, num;
 
224
 
 
225
    num = ctk_display_device->num_display_devices;
 
226
 
 
227
    if (num == 1) {
 
228
        title = "Display Device Help";
 
229
        page = "page";
 
230
    } else {
 
231
        title = "Display Devices Help";
 
232
        page = "pages";
 
233
    }
 
234
 
 
235
    /* ugliness to build list of display device names */
 
236
 
 
237
    s = NULL;
 
238
    for (n = 0; n < num; n++) {
 
239
        
 
240
        name = ctk_display_device->display_device_names[n];
 
241
 
 
242
        if (s) {
 
243
            tmp = s;
 
244
            s = g_strconcat(s, " ", NULL);
 
245
            g_free(tmp);
 
246
        } else {
 
247
            s = g_strdup(" ");
 
248
        }
 
249
        
 
250
        tmp = s;
 
251
 
 
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);
 
256
        } else {
 
257
            s = g_strconcat(s, name, ",", NULL);
 
258
        }
 
259
        
 
260
        g_free(tmp);
 
261
    }
 
262
 
 
263
 
 
264
    b = gtk_text_buffer_new(table);
 
265
    
 
266
    gtk_text_buffer_get_iter_at_offset(b, &i, 0);
 
267
 
 
268
    ctk_help_title(b, &i, title);
 
269
    
 
270
    ctk_help_para(b, &i, "The %s page is a place holder until support "
 
271
                  "for configuring TwinView is added.", title);
 
272
    
 
273
    ctk_help_para(b, &i, "Please see the %s for%s for per-display device "
 
274
                  "configuration.", page, s);
 
275
    
 
276
    ctk_help_finish(b);
 
277
 
 
278
    return b;
 
279
    
 
280
} /* ctk_display_device_create_help() */