~ubuntu-branches/ubuntu/quantal/nvidia-settings/quantal

« back to all changes in this revision

Viewing changes to src/gtk+-2.x/ctkdisplaydevice-crt.c

  • Committer: Package Import Robot
  • Author(s): Alberto Milone
  • Date: 2012-06-25 16:31:12 UTC
  • mfrom: (1.1.22)
  • Revision ID: package-import@ubuntu.com-20120625163112-0au9uusymifzjtku
Tags: 302.17-0ubuntu1
* New upstream release.
* Refresh 04_nvidia-settings_natty_ftbs.patch.
* Drop 02_nvidia-settings-format-string.patch which
  is now upstream.
* debian/rules:
  - Make sure to install the new sources correctly.

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 modify it
8
 
 * under the terms and conditions of the GNU General Public License,
9
 
 * version 2, as published by the Free Software Foundation.
10
 
 *
11
 
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
 
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14
 
 * more details.
15
 
 *
16
 
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program.  If not, see <http://www.gnu.org/licenses>.
18
 
 */
19
 
 
20
 
#include <gtk/gtk.h>
21
 
#include <NvCtrlAttributes.h>
22
 
 
23
 
#include "ctkbanner.h"
24
 
 
25
 
#include "ctkdisplaydevice-crt.h"
26
 
 
27
 
#include "ctkimagesliders.h"
28
 
#include "ctkedid.h"
29
 
#include "ctkconfig.h"
30
 
#include "ctkhelp.h"
31
 
#include "ctkutils.h"
32
 
#include <stdio.h>
33
 
 
34
 
static void ctk_display_device_crt_class_init(CtkDisplayDeviceCrtClass *);
35
 
static void ctk_display_device_crt_finalize(GObject *);
36
 
 
37
 
static void reset_button_clicked(GtkButton *button, gpointer user_data);
38
 
 
39
 
static void ctk_display_device_crt_setup(CtkDisplayDeviceCrt
40
 
                                         *ctk_display_device_crt);
41
 
 
42
 
static void info_update_received(GtkObject *object, gpointer arg1,
43
 
                                 gpointer user_data);
44
 
 
45
 
static void crt_info_setup(CtkDisplayDeviceCrt *ctk_display_device_crt);
46
 
 
47
 
static void enabled_displays_received(GtkObject *object, gpointer arg1,
48
 
                                      gpointer user_data);
49
 
 
50
 
static const char * __refresh_rate_help = "The refresh rate displays the "
51
 
"rate at which the screen is currently refreshing the image.";
52
 
 
53
 
GType ctk_display_device_crt_get_type(void)
54
 
{
55
 
    static GType ctk_display_device_crt_type = 0;
56
 
    
57
 
    if (!ctk_display_device_crt_type) {
58
 
        static const GTypeInfo ctk_display_device_crt_info = {
59
 
            sizeof (CtkDisplayDeviceCrtClass),
60
 
            NULL, /* base_init */
61
 
            NULL, /* base_finalize */
62
 
            (GClassInitFunc) ctk_display_device_crt_class_init,
63
 
            NULL, /* class_finalize */
64
 
            NULL, /* class_data */
65
 
            sizeof (CtkDisplayDeviceCrt),
66
 
            0, /* n_preallocs */
67
 
            NULL, /* instance_init */
68
 
        };
69
 
 
70
 
        ctk_display_device_crt_type = g_type_register_static (GTK_TYPE_VBOX,
71
 
                "CtkDisplayDeviceCrt", &ctk_display_device_crt_info, 0);
72
 
    }
73
 
 
74
 
    return ctk_display_device_crt_type;
75
 
}
76
 
 
77
 
static void ctk_display_device_crt_class_init(
78
 
    CtkDisplayDeviceCrtClass *ctk_display_device_crt_class
79
 
)
80
 
{
81
 
    GObjectClass *gobject_class = (GObjectClass *)ctk_display_device_crt_class;
82
 
    gobject_class->finalize = ctk_display_device_crt_finalize;
83
 
}
84
 
 
85
 
static void ctk_display_device_crt_finalize(
86
 
    GObject *object
87
 
)
88
 
{
89
 
    CtkDisplayDeviceCrt *ctk_display_device_crt = CTK_DISPLAY_DEVICE_CRT(object);
90
 
    g_free(ctk_display_device_crt->name);
91
 
    g_signal_handlers_disconnect_matched(ctk_display_device_crt->ctk_event,
92
 
                                         G_SIGNAL_MATCH_DATA,
93
 
                                         0,
94
 
                                         0,
95
 
                                         NULL,
96
 
                                         NULL,
97
 
                                         (gpointer) ctk_display_device_crt);
98
 
}
99
 
 
100
 
/*
101
 
 * ctk_display_device_crt_new() - constructor for the CRT display
102
 
 * device page.
103
 
 */
104
 
 
105
 
GtkWidget* ctk_display_device_crt_new(NvCtrlAttributeHandle *handle,
106
 
                                      CtkConfig *ctk_config,
107
 
                                      CtkEvent *ctk_event,
108
 
                                      unsigned int display_device_mask,
109
 
                                      char *name)
110
 
{
111
 
    GObject *object;
112
 
    CtkDisplayDeviceCrt *ctk_display_device_crt;
113
 
    GtkWidget *banner;
114
 
    GtkWidget *hbox;
115
 
    GtkWidget *tmpbox;
116
 
    GtkWidget *tmphbox, *eventbox;
117
 
    GtkWidget *frame;
118
 
    GtkWidget *alignment;
119
 
 
120
 
    object = g_object_new(CTK_TYPE_DISPLAY_DEVICE_CRT, NULL);
121
 
    if (!object) return NULL;
122
 
 
123
 
    ctk_display_device_crt = CTK_DISPLAY_DEVICE_CRT(object);
124
 
    ctk_display_device_crt->handle = handle;
125
 
    ctk_display_device_crt->ctk_config = ctk_config;
126
 
    ctk_display_device_crt->ctk_event = ctk_event;
127
 
    ctk_display_device_crt->display_device_mask = display_device_mask;
128
 
    ctk_display_device_crt->name = g_strdup(name);
129
 
    ctk_display_device_crt->txt_refresh_rate = gtk_label_new("");
130
 
    gtk_box_set_spacing(GTK_BOX(object), 10);
131
 
    
132
 
    /* banner */
133
 
 
134
 
    banner = ctk_banner_image_new(BANNER_ARTWORK_CRT);
135
 
    gtk_box_pack_start(GTK_BOX(object), banner, FALSE, FALSE, 0);
136
 
 
137
 
    /*
138
 
     * create the reset button (which we need while creating the
139
 
     * controls in this page so that we can set the button's
140
 
     * sensitivity), though we pack it at the bottom of the page
141
 
     */
142
 
 
143
 
    ctk_display_device_crt->reset_button =
144
 
        gtk_button_new_with_label("Reset CRT Hardware Defaults");
145
 
 
146
 
    alignment = gtk_alignment_new(1, 1, 0, 0);
147
 
    gtk_container_add(GTK_CONTAINER(alignment),
148
 
                      ctk_display_device_crt->reset_button);
149
 
    gtk_box_pack_end(GTK_BOX(object), alignment, TRUE, TRUE, 0);
150
 
    
151
 
    g_signal_connect(G_OBJECT(ctk_display_device_crt->reset_button),
152
 
                     "clicked", G_CALLBACK(reset_button_clicked),
153
 
                     (gpointer) ctk_display_device_crt);
154
 
 
155
 
    ctk_config_set_tooltip(ctk_config, ctk_display_device_crt->reset_button,
156
 
                           ctk_help_create_reset_hardware_defaults_text("CRT", name));
157
 
    
158
 
    /* pack the image sliders */
159
 
    
160
 
    ctk_display_device_crt->image_sliders =
161
 
        ctk_image_sliders_new(handle, ctk_config, ctk_event,
162
 
                              ctk_display_device_crt->reset_button,
163
 
                              display_device_mask, name);
164
 
    if (ctk_display_device_crt->image_sliders) {
165
 
        gtk_box_pack_start(GTK_BOX(object),
166
 
                           ctk_display_device_crt->image_sliders,
167
 
                           FALSE, FALSE, 0);
168
 
    }
169
 
    /* add the label Refresh Rate and its value */
170
 
        
171
 
    frame = gtk_frame_new(NULL);
172
 
    gtk_box_pack_start(GTK_BOX(object), frame, FALSE, FALSE, 0);
173
 
    tmphbox = gtk_hbox_new(FALSE, 0);
174
 
    gtk_container_set_border_width(GTK_CONTAINER(tmphbox), 5);
175
 
    gtk_container_add(GTK_CONTAINER(frame), tmphbox);
176
 
        
177
 
    tmpbox = gtk_vbox_new(FALSE, 5);
178
 
    gtk_container_add(GTK_CONTAINER(tmphbox), tmpbox);
179
 
    
180
 
    /* pack the Refresh Rate Label */
181
 
    {
182
 
        typedef struct {
183
 
            GtkWidget *label;
184
 
            GtkWidget *txt;
185
 
            const gchar *tooltip;
186
 
        } TextLineInfo;
187
 
 
188
 
        TextLineInfo line = {
189
 
            gtk_label_new("Refresh Rate:"),
190
 
            ctk_display_device_crt->txt_refresh_rate,
191
 
            __refresh_rate_help,
192
 
        };
193
 
    
194
 
        hbox = gtk_hbox_new(FALSE, 0);
195
 
        gtk_box_pack_start(GTK_BOX(hbox), line.label,
196
 
                               FALSE, FALSE, 0);
197
 
        gtk_box_pack_start(GTK_BOX(hbox), line.txt,
198
 
                               FALSE, FALSE, 5);
199
 
 
200
 
        /* Include tooltips */
201
 
        if (!line.tooltip) {
202
 
            gtk_box_pack_start(GTK_BOX(tmpbox), hbox, FALSE, FALSE, 0);
203
 
        } else {
204
 
            eventbox = gtk_event_box_new();
205
 
            gtk_container_add(GTK_CONTAINER(eventbox), hbox);
206
 
            ctk_config_set_tooltip(ctk_config, eventbox, line.tooltip);
207
 
            gtk_box_pack_start(GTK_BOX(tmpbox), eventbox, FALSE, FALSE, 0);
208
 
        }
209
 
    }
210
 
    /* pack the EDID button */
211
 
 
212
 
    hbox = gtk_hbox_new(FALSE, 0);
213
 
    gtk_box_pack_start(GTK_BOX(object), hbox, FALSE, FALSE, 0);
214
 
    ctk_display_device_crt->edid_box = hbox;
215
 
    
216
 
    /* show the page */
217
 
 
218
 
    gtk_widget_show_all(GTK_WIDGET(object));
219
 
 
220
 
    /* Update the GUI */
221
 
 
222
 
    update_display_enabled_flag(ctk_display_device_crt->handle,
223
 
                                &ctk_display_device_crt->display_enabled,
224
 
                                ctk_display_device_crt->display_device_mask);
225
 
 
226
 
    ctk_display_device_crt_setup(ctk_display_device_crt);
227
 
    
228
 
    /* handle enable/disable events on the display device */
229
 
 
230
 
    g_signal_connect(G_OBJECT(ctk_event),
231
 
                     CTK_EVENT_NAME(NV_CTRL_ENABLED_DISPLAYS),
232
 
                     G_CALLBACK(enabled_displays_received),
233
 
                     (gpointer) ctk_display_device_crt);
234
 
 
235
 
    g_signal_connect(G_OBJECT(ctk_event),
236
 
                     CTK_EVENT_NAME(NV_CTRL_REFRESH_RATE),
237
 
                     G_CALLBACK(info_update_received),
238
 
                     (gpointer) ctk_display_device_crt);
239
 
    
240
 
    return GTK_WIDGET(object);
241
 
}
242
 
 
243
 
 
244
 
 
245
 
GtkTextBuffer *ctk_display_device_crt_create_help(GtkTextTagTable *table,
246
 
                                                  CtkDisplayDeviceCrt
247
 
                                                  *ctk_display_device_crt)
248
 
{
249
 
    GtkTextIter i;
250
 
    GtkTextBuffer *b;
251
 
    GtkTooltipsData *td;
252
 
 
253
 
    b = gtk_text_buffer_new(table);
254
 
    
255
 
    gtk_text_buffer_get_iter_at_offset(b, &i, 0);
256
 
 
257
 
    ctk_help_title(b, &i, "%s Help", ctk_display_device_crt->name);
258
 
    
259
 
    ctk_help_heading(b, &i, "Refresh rate");
260
 
    ctk_help_para(b, &i, __refresh_rate_help);
261
 
        
262
 
    add_image_sliders_help
263
 
        (CTK_IMAGE_SLIDERS(ctk_display_device_crt->image_sliders), b, &i);
264
 
 
265
 
    if (ctk_display_device_crt->edid) {
266
 
        add_acquire_edid_help(b, &i);
267
 
    }
268
 
    
269
 
    td = gtk_tooltips_data_get(GTK_WIDGET(ctk_display_device_crt->reset_button));
270
 
    ctk_help_reset_hardware_defaults (b, &i, td->tip_text);
271
 
 
272
 
    ctk_help_finish(b);
273
 
 
274
 
    return b;
275
 
}
276
 
 
277
 
 
278
 
 
279
 
/*
280
 
 * reset_button_clicked() -
281
 
 */
282
 
 
283
 
static void reset_button_clicked(GtkButton *button, gpointer user_data)
284
 
{
285
 
    CtkDisplayDeviceCrt *ctk_display_device_crt =
286
 
        CTK_DISPLAY_DEVICE_CRT(user_data);
287
 
    
288
 
    ctk_image_sliders_reset
289
 
        (CTK_IMAGE_SLIDERS(ctk_display_device_crt->image_sliders));
290
 
 
291
 
    gtk_widget_set_sensitive(ctk_display_device_crt->reset_button, FALSE);
292
 
    
293
 
    ctk_config_statusbar_message(ctk_display_device_crt->ctk_config,
294
 
                                 "Reset hardware defaults for %s.",
295
 
                                 ctk_display_device_crt->name);
296
 
 
297
 
} /* reset_button_clicked() */
298
 
 
299
 
 
300
 
 
301
 
/*
302
 
 * Updates the display device page to reflect the current
303
 
 * configuration of the display device.
304
 
 */
305
 
static void ctk_display_device_crt_setup(CtkDisplayDeviceCrt
306
 
                                         *ctk_display_device_crt)
307
 
{
308
 
    /* Update CRT-specific settings */
309
 
    crt_info_setup(ctk_display_device_crt);
310
 
    
311
 
    /* Update the image sliders */
312
 
 
313
 
    ctk_image_sliders_setup
314
 
        (CTK_IMAGE_SLIDERS(ctk_display_device_crt->image_sliders));
315
 
 
316
 
 
317
 
    /* update acquire EDID button */
318
 
    
319
 
    if (ctk_display_device_crt->edid) {
320
 
        GList *list;
321
 
            
322
 
        list = gtk_container_get_children
323
 
                (GTK_CONTAINER(ctk_display_device_crt->edid_box));
324
 
        if (list) {
325
 
            gtk_container_remove
326
 
                (GTK_CONTAINER(ctk_display_device_crt->edid_box),
327
 
                 (GtkWidget *)(list->data));
328
 
            g_list_free(list);
329
 
        }
330
 
    }
331
 
 
332
 
    ctk_display_device_crt->edid =
333
 
        ctk_edid_new(ctk_display_device_crt->handle,
334
 
                     ctk_display_device_crt->ctk_config,
335
 
                     ctk_display_device_crt->ctk_event,
336
 
                     ctk_display_device_crt->reset_button,
337
 
                     ctk_display_device_crt->display_device_mask,
338
 
                     ctk_display_device_crt->name);
339
 
 
340
 
    if (ctk_display_device_crt->edid) {
341
 
        gtk_box_pack_start(GTK_BOX(ctk_display_device_crt->edid_box),
342
 
                           ctk_display_device_crt->edid, TRUE, TRUE, 0);
343
 
    }
344
 
 
345
 
 
346
 
    /* update the reset button */
347
 
 
348
 
    gtk_widget_set_sensitive(ctk_display_device_crt->reset_button, FALSE);
349
 
 
350
 
} /* ctk_display_device_crt_setup() */
351
 
 
352
 
static void crt_info_setup(CtkDisplayDeviceCrt *ctk_display_device_crt)
353
 
{
354
 
    ReturnStatus ret;
355
 
    gint val;
356
 
    
357
 
    /* Refresh Rate */
358
 
    ret = NvCtrlGetDisplayAttribute(ctk_display_device_crt->handle,
359
 
                                    ctk_display_device_crt->display_device_mask,
360
 
                                    NV_CTRL_REFRESH_RATE, &val);
361
 
    if (ret == NvCtrlSuccess) {
362
 
        char str[32];
363
 
        float fvalue = ((float)(val)) / 100.0f;
364
 
        snprintf(str, 32, "%.2f Hz", fvalue);
365
 
        gtk_label_set_text
366
 
                    (GTK_LABEL(ctk_display_device_crt->txt_refresh_rate),
367
 
                     str);
368
 
    } else {
369
 
        gtk_label_set_text
370
 
                  (GTK_LABEL(ctk_display_device_crt->txt_refresh_rate),
371
 
                   "Unknown");
372
 
    }
373
 
}
374
 
/*
375
 
 * When the list of enabled displays on the GPU changes,
376
 
 * this page should disable/enable access based on whether
377
 
 * or not the display device is enabled.
378
 
 */
379
 
static void enabled_displays_received(GtkObject *object, gpointer arg1,
380
 
                                      gpointer user_data)
381
 
{
382
 
    CtkDisplayDeviceCrt *ctk_object = CTK_DISPLAY_DEVICE_CRT(user_data);
383
 
 
384
 
    /* Requery display information only if display disabled */
385
 
 
386
 
    update_display_enabled_flag(ctk_object->handle,
387
 
                                &ctk_object->display_enabled,
388
 
                                ctk_object->display_device_mask);
389
 
 
390
 
    if (ctk_object->display_enabled) {
391
 
        return;
392
 
    }
393
 
 
394
 
    ctk_display_device_crt_setup(ctk_object);
395
 
 
396
 
} /* enabled_displays_received() */
397
 
 
398
 
 
399
 
/*
400
 
 * When resolution changes occur, we should update the GUI to reflect 
401
 
 * the current state.
402
 
 */
403
 
 
404
 
static void info_update_received(GtkObject *object, gpointer arg1,
405
 
                                 gpointer user_data)
406
 
{
407
 
    CtkDisplayDeviceCrt *ctk_object = CTK_DISPLAY_DEVICE_CRT(user_data);
408
 
    CtkEventStruct *event_struct = (CtkEventStruct *) arg1;
409
 
    
410
 
    /* if the event is not for this display device, return */
411
 
    if (!(event_struct->display_mask & ctk_object->display_device_mask)) {
412
 
        return;
413
 
    }
414
 
    crt_info_setup(ctk_object);
415
 
}