1 /* mate-rr.h
2  *
3  * Copyright 2007, 2008, Red Hat, Inc.
4  *
5  * This file is part of the Mate Library.
6  *
7  * The Mate Library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * The Mate Library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with the Mate Library; see the file COPYING.LIB.  If not,
19  * write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20  * Boston, MA  02110-1301, USA.
21  *
22  * Author: Soren Sandmann <sandmann@redhat.com>
23  */
24 #ifndef MATE_RR_H
25 #define MATE_RR_H
26 
27 #ifndef MATE_DESKTOP_USE_UNSTABLE_API
28 #error    MateRR is unstable API. You must define MATE_DESKTOP_USE_UNSTABLE_API before including materr.h
29 #endif
30 
31 #include <glib.h>
32 #include <gdk/gdk.h>
33 
34 typedef struct MateRRScreenPrivate MateRRScreenPrivate;
35 typedef struct MateRROutput MateRROutput;
36 typedef struct MateRRCrtc MateRRCrtc;
37 typedef struct MateRRMode MateRRMode;
38 
39 typedef struct {
40     GObject parent;
41 
42     MateRRScreenPrivate* priv;
43 } MateRRScreen;
44 
45 typedef struct {
46     GObjectClass parent_class;
47 
48         void (* changed) (void);
49 } MateRRScreenClass;
50 
51 typedef enum
52 {
53     MATE_RR_ROTATION_0 =	(1 << 0),
54     MATE_RR_ROTATION_90 =	(1 << 1),
55     MATE_RR_ROTATION_180 =	(1 << 2),
56     MATE_RR_ROTATION_270 =	(1 << 3),
57     MATE_RR_REFLECT_X =	(1 << 4),
58     MATE_RR_REFLECT_Y =	(1 << 5)
59 } MateRRRotation;
60 
61 /* Error codes */
62 
63 #define MATE_RR_ERROR (mate_rr_error_quark ())
64 
65 GQuark mate_rr_error_quark (void);
66 
67 typedef enum {
68     MATE_RR_ERROR_UNKNOWN,		/* generic "fail" */
69     MATE_RR_ERROR_NO_RANDR_EXTENSION,	/* RANDR extension is not present */
70     MATE_RR_ERROR_RANDR_ERROR,		/* generic/undescribed error from the underlying XRR API */
71     MATE_RR_ERROR_BOUNDS_ERROR,	/* requested bounds of a CRTC are outside the maximum size */
72     MATE_RR_ERROR_CRTC_ASSIGNMENT,	/* could not assign CRTCs to outputs */
73     MATE_RR_ERROR_NO_MATCHING_CONFIG,	/* none of the saved configurations matched the current configuration */
74 } MateRRError;
75 
76 #define MATE_RR_CONNECTOR_TYPE_PANEL "Panel"  /* This is a laptop's built-in LCD */
77 
78 #define MATE_TYPE_RR_SCREEN                  (mate_rr_screen_get_type())
79 #define MATE_RR_SCREEN(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), MATE_TYPE_RR_SCREEN, MateRRScreen))
80 #define MATE_IS_RR_SCREEN(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MATE_TYPE_RR_SCREEN))
81 #define MATE_RR_SCREEN_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), MATE_TYPE_RR_SCREEN, MateRRScreenClass))
82 #define MATE_IS_RR_SCREEN_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), MATE_TYPE_RR_SCREEN))
83 #define MATE_RR_SCREEN_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), MATE_TYPE_RR_SCREEN, MateRRScreenClass))
84 
85 #define MATE_TYPE_RR_OUTPUT (mate_rr_output_get_type())
86 #define MATE_TYPE_RR_CRTC   (mate_rr_crtc_get_type())
87 #define MATE_TYPE_RR_MODE   (mate_rr_mode_get_type())
88 
89 GType mate_rr_screen_get_type (void);
90 GType mate_rr_output_get_type (void);
91 GType mate_rr_crtc_get_type (void);
92 GType mate_rr_mode_get_type (void);
93 
94 /* MateRRScreen */
95 MateRRScreen * mate_rr_screen_new                (GdkScreen             *screen,
96 						    GError               **error);
97 MateRROutput **mate_rr_screen_list_outputs       (MateRRScreen         *screen);
98 MateRRCrtc **  mate_rr_screen_list_crtcs         (MateRRScreen         *screen);
99 MateRRMode **  mate_rr_screen_list_modes         (MateRRScreen         *screen);
100 MateRRMode **  mate_rr_screen_list_clone_modes   (MateRRScreen	  *screen);
101 void            mate_rr_screen_set_size           (MateRRScreen         *screen,
102 						    int                    width,
103 						    int                    height,
104 						    int                    mm_width,
105 						    int                    mm_height);
106 MateRRCrtc *   mate_rr_screen_get_crtc_by_id     (MateRRScreen         *screen,
107 						    guint32                id);
108 gboolean        mate_rr_screen_refresh            (MateRRScreen         *screen,
109 						    GError               **error);
110 MateRROutput * mate_rr_screen_get_output_by_id   (MateRRScreen         *screen,
111 						    guint32                id);
112 MateRROutput * mate_rr_screen_get_output_by_name (MateRRScreen         *screen,
113 						    const char            *name);
114 void            mate_rr_screen_get_ranges         (MateRRScreen         *screen,
115 						    int                   *min_width,
116 						    int                   *max_width,
117 						    int                   *min_height,
118 						    int                   *max_height);
119 void            mate_rr_screen_get_timestamps     (MateRRScreen         *screen,
120 						    guint32               *change_timestamp_ret,
121 						    guint32               *config_timestamp_ret);
122 
123 void            mate_rr_screen_set_primary_output (MateRRScreen         *screen,
124                                                     MateRROutput         *output);
125 
126 /* MateRROutput */
127 guint32         mate_rr_output_get_id             (MateRROutput         *output);
128 const char *    mate_rr_output_get_name           (MateRROutput         *output);
129 gboolean        mate_rr_output_is_connected       (MateRROutput         *output);
130 int             mate_rr_output_get_size_inches    (MateRROutput         *output);
131 int             mate_rr_output_get_width_mm       (MateRROutput         *outout);
132 int             mate_rr_output_get_height_mm      (MateRROutput         *output);
133 const guint8 *  mate_rr_output_get_edid_data      (MateRROutput         *output);
134 MateRRCrtc **  mate_rr_output_get_possible_crtcs (MateRROutput         *output);
135 MateRRMode *   mate_rr_output_get_current_mode   (MateRROutput         *output);
136 MateRRCrtc *   mate_rr_output_get_crtc           (MateRROutput         *output);
137 const char *    mate_rr_output_get_connector_type (MateRROutput         *output);
138 gboolean        mate_rr_output_is_laptop          (MateRROutput         *output);
139 void            mate_rr_output_get_position       (MateRROutput         *output,
140 						    int                   *x,
141 						    int                   *y);
142 gboolean        mate_rr_output_can_clone          (MateRROutput         *output,
143 						    MateRROutput         *clone);
144 MateRRMode **  mate_rr_output_list_modes         (MateRROutput         *output);
145 MateRRMode *   mate_rr_output_get_preferred_mode (MateRROutput         *output);
146 gboolean        mate_rr_output_supports_mode      (MateRROutput         *output,
147 						    MateRRMode           *mode);
148 gboolean        mate_rr_output_get_is_primary     (MateRROutput         *output);
149 
150 /* MateRRMode */
151 guint32         mate_rr_mode_get_id               (MateRRMode           *mode);
152 guint           mate_rr_mode_get_width            (MateRRMode           *mode);
153 guint           mate_rr_mode_get_height           (MateRRMode           *mode);
154 int             mate_rr_mode_get_freq             (MateRRMode           *mode);
155 
156 /* MateRRCrtc */
157 guint32         mate_rr_crtc_get_id               (MateRRCrtc           *crtc);
158 
159 #ifndef MATE_DISABLE_DEPRECATED
160 gboolean        mate_rr_crtc_set_config           (MateRRCrtc           *crtc,
161 						    int                    x,
162 						    int                    y,
163 						    MateRRMode           *mode,
164 						    MateRRRotation        rotation,
165 						    MateRROutput        **outputs,
166 						    int                    n_outputs,
167 						    GError               **error);
168 #endif
169 
170 gboolean        mate_rr_crtc_set_config_with_time (MateRRCrtc           *crtc,
171 						    guint32                timestamp,
172 						    int                    x,
173 						    int                    y,
174 						    MateRRMode           *mode,
175 						    MateRRRotation        rotation,
176 						    MateRROutput        **outputs,
177 						    int                    n_outputs,
178 						    GError               **error);
179 gboolean        mate_rr_crtc_can_drive_output     (MateRRCrtc           *crtc,
180 						    MateRROutput         *output);
181 MateRRMode *   mate_rr_crtc_get_current_mode     (MateRRCrtc           *crtc);
182 void            mate_rr_crtc_get_position         (MateRRCrtc           *crtc,
183 						    int                   *x,
184 						    int                   *y);
185 MateRRRotation mate_rr_crtc_get_current_rotation (MateRRCrtc           *crtc);
186 MateRRRotation mate_rr_crtc_get_rotations        (MateRRCrtc           *crtc);
187 gboolean        mate_rr_crtc_supports_rotation    (MateRRCrtc           *crtc,
188 						    MateRRRotation        rotation);
189 
190 gboolean        mate_rr_crtc_get_gamma            (MateRRCrtc           *crtc,
191 						    int                   *size,
192 						    unsigned short       **red,
193 						    unsigned short       **green,
194 						    unsigned short       **blue);
195 void            mate_rr_crtc_set_gamma            (MateRRCrtc           *crtc,
196 						    int                    size,
197 						    unsigned short        *red,
198 						    unsigned short        *green,
199 						    unsigned short        *blue);
200 #endif /* MATE_RR_H */
201