summaryrefslogtreecommitdiff
path: root/capplets/display
diff options
context:
space:
mode:
Diffstat (limited to 'capplets/display')
-rw-r--r--capplets/display/Makefile.am78
-rw-r--r--capplets/display/TODO837
-rw-r--r--capplets/display/display-capplet.ui437
-rw-r--r--capplets/display/display-properties.desktop.in.in14
-rw-r--r--capplets/display/foo-marshal.c279
-rw-r--r--capplets/display/foo-marshal.h67
-rw-r--r--capplets/display/icons/16x16/mate-preferences-desktop-display.pngbin0 -> 613 bytes
-rw-r--r--capplets/display/icons/22x22/mate-preferences-desktop-display.pngbin0 -> 866 bytes
-rw-r--r--capplets/display/icons/24x24/mate-preferences-desktop-display.pngbin0 -> 909 bytes
-rw-r--r--capplets/display/icons/32x32/mate-preferences-desktop-display.pngbin0 -> 1602 bytes
-rw-r--r--capplets/display/icons/scalable/mate-preferences-desktop-display.svg470
-rw-r--r--capplets/display/mate-display-properties-install-systemwide.c272
-rw-r--r--capplets/display/org.mate.randr.policy.in29
-rw-r--r--capplets/display/scrollarea.c1944
-rw-r--r--capplets/display/scrollarea.h124
-rw-r--r--capplets/display/xrandr-capplet.c2571
16 files changed, 7122 insertions, 0 deletions
diff --git a/capplets/display/Makefile.am b/capplets/display/Makefile.am
new file mode 100644
index 00000000..70f417c7
--- /dev/null
+++ b/capplets/display/Makefile.am
@@ -0,0 +1,78 @@
+# This is used in MATECC_CAPPLETS_CFLAGS
+cappletname = display
+
+uidir = $(pkgdatadir)/ui
+dist_ui_DATA = display-capplet.ui
+
+bin_PROGRAMS = mate-display-properties
+
+sbin_PROGRAMS = mate-display-properties-install-systemwide
+
+mate_display_properties_SOURCES = \
+ xrandr-capplet.c \
+ scrollarea.c \
+ foo-marshal.c \
+ scrollarea.h \
+ foo-marshal.h
+
+mate_display_properties_LDFLAGS = -export-dynamic
+mate_display_properties_LDADD = \
+ $(top_builddir)/capplets/common/libcommon.la \
+ $(DISPLAY_CAPPLET_LIBS)
+
+mate_display_properties_install_systemwide_SOURCES = \
+ mate-display-properties-install-systemwide.c
+
+mate_display_properties_install_systemwide_LDADD = \
+ $(GLIB_LIBS)
+
+polkit_policydir = $(datadir)/polkit-1/actions
+dist_polkit_policy_DATA = \
+ org.mate.randr.policy
+
+# You will need a recent intltool or the patch from this bug
+# http://bugzilla.gnome.org/show_bug.cgi?id=462312
+@INTLTOOL_POLICY_RULE@
+
+@INTLTOOL_DESKTOP_RULE@
+
+icons16dir = $(datadir)/icons/hicolor/16x16/apps
+dist_icons16_DATA = icons/16x16/mate-preferences-desktop-display.png
+icons22dir = $(datadir)/icons/hicolor/22x22/apps
+dist_icons22_DATA = icons/22x22/mate-preferences-desktop-display.png
+icons24dir = $(datadir)/icons/hicolor/24x24/apps
+dist_icons24_DATA = icons/24x24/mate-preferences-desktop-display.png
+icons32dir = $(datadir)/icons/hicolor/32x32/apps
+dist_icons32_DATA = icons/32x32/mate-preferences-desktop-display.png
+iconssvgdir = $(datadir)/icons/hicolor/scalable/apps
+dist_iconssvg_DATA = icons/scalable/mate-preferences-desktop-display.svg
+
+desktopdir = $(datadir)/applications
+Desktop_in_files = display-properties.desktop.in
+desktop_DATA = $(Desktop_in_files:.desktop.in=.desktop)
+
+INCLUDES = $(DISPLAY_CAPPLET_CFLAGS) \
+ $(MATECC_CAPPLETS_CFLAGS) \
+ -DSBINDIR="\"$(sbindir)\"" \
+ -DUIDIR="\"$(uidir)\"" \
+ -DMATELOCALEDIR="\"$(datadir)/locale\"" \
+ -DMATECC_DATA_DIR="\"$(pkgdatadir)\""
+
+CLEANFILES = $(MATECC_CAPPLETS_CLEANFILES) $(Desktop_in_files) $(desktop_DATA)
+
+gtk_update_icon_cache = gtk-update-icon-cache -f -t $(datadir)/icons/hicolor
+install-data-hook: update-icon-cache
+uninstall-hook: update-icon-cache
+update-icon-cache:
+ @-if test -z "$(DESTDIR)"; then \
+ echo "Updating Gtk icon cache."; \
+ $(gtk_update_icon_cache); \
+ else \
+ echo "*** Icon cache not updated. After (un)install, run this:"; \
+ echo "*** $(gtk_update_icon_cache)"; \
+ fi
+
+EXTRA_DIST = org.mate.randr.policy.in
+DISTCLEANFILES = org.mate.randr.policy
+
+-include $(top_srcdir)/git.mk
diff --git a/capplets/display/TODO b/capplets/display/TODO
new file mode 100644
index 00000000..08f9e21b
--- /dev/null
+++ b/capplets/display/TODO
@@ -0,0 +1,837 @@
+Highlevel overview:
+
+Tablet rotation things
+only when there is a tablet attached.
+
+Here is the OS X Display menu:
+
+ Detect Displays
+ Turn on mirroring
+ --------------------------
+ SyncMaster
+ - 1280 x 1024, 60 Hz, Millions
+ - 1344 x ...
+ --------------------------------
+ Color LCD
+ - 1024 x 1024 ...
+ --------------------------
+ Displays Preferences
+
+ Color LCD means "laptop panel".
+
+- GTK+ work.
+
+ Allow applications to be notified whenever monitors are added
+ or removed. Allow applications to get more detailed
+ information about the connected monitors.
+
+ The main complication is that XRRGetScreenResources() is very
+ slow. We could call it only when the X server sends an event,
+ but it's not desirable to have every application freeze for
+ half a second. And certainly not desirable to have the X
+ server block for n * 0.5 seconds.
+
+ With the X server work below we should be fine just calling
+ XRRGetScreenResources on startup and in response to events.
+
+- X server work:
+
+ X server needs to poll for whether a monitor is plugged
+ in. Whenever it detects a change, it should do an EDID query,
+ and cache the resulting information. That way XRRGetScreenResources()
+ can be the speed of a normal roundtrip. It's desirable that
+ normal client requests can still be processed during the EDID
+ querying, but only a nice-to-have.
+
+ Drivers need to work reliably. There could be substantial work
+ here. For F9, possibly only the Intel driver can be made to
+ work.
+
+ Interrupts and events must be generated whenever something changes
+ about the outputs, if necessary by polling.
+
+ Events must be emitted whenever something changes, including when
+ the reason for the change is a manual change.
+
+ The maximum framebuffer must be dynamically changable.
+
+- Control panel work:
+ Capplet needs to be written. The main complications:
+
+ - It needs to pay attention to events from the X server
+ and update itself, ie., add show new monitors if they become
+ available when the applet is shown.
+
+ - It needs to store information under a key computed
+ from a monitor identifier. The complication here is that
+ it's not completely clear how to do this in MateConf.
+
+ - Would probably be worthwhile to drop libmate/libmateui from
+ the craplets.
+
+- Marco work:
+ - Marco is already Xinerama aware, but it needs to update itself
+ when monitors come and go.
+
+- MATE panel work:
+ - Is already Xinerama aware, but needs to listen and update itself
+ when monitors change.
+
+- Evince work:
+ - Make sure it deals sensibly with multiple monitors
+
+- OpenOffice work:
+ - Make sure it deals sensibly with multiple monitors
+
+- An Xlib call to just return all the available information would be
+ useful. At the moment we have to do a bunch of roundtrips to
+ get the information. This is a would-be-nice though.
+
+- A dbus service could be written that pops up the applet whenever a
+ monitor. It should only pop up if the new monitor is unknown. This
+ is at best a nice-to-have, and low priority in my opinion.
+
+
+******************* Marco
+
+Havoc:
+
+> I was just talking to bryan about this and "helping" him design it ;-)
+
+> But I wanted to be sure and lobby for a fix window managers
+> need. Basically right now the WM can't tell "physical" from
+> "logical" monitors.
+
+> A "logical" monitor is a desktop; it has its own panel, windows
+> maximize to it, etc.
+
+> A "physical" monitor is a piece of hardware.
+
+> Sometimes people want to combine physical monitors into a video wall
+> or just two monitors treated as one. Or at least a couple of noisy
+> people in bugzilla want to do this.
+
+> When people talk about a "Xinerama aware" app or WM they usually
+> mean that all physical monitors are treated as logical monitors,
+> while lack of Xinerama-aware means treating the entire X screen (all
+> physical monitors) as one logical monitor.
+
+> The problem is that the setting for "ignore Xinerama" or "don't be
+> Xinerama aware" should be global to the desktop (GTK, all apps, WM)
+> and should not be a window manager setting.
+
+> Bryan thought people who wanted non-Xinerama-aware should just use
+> fvwm, which may be right, but what I'd say is that if there is any
+> setting for this, it should be desktop-global and in this monitor
+> config dialog.
+
+> It should not be a marco or Compiz option, but in some way an X
+> option in short. The implementation could be either an X server
+> feature or an EWMH hint or whatever, but it should be controlled by
+> the monitor config dialog and used by apps, GTK, etc. in addition to
+> used by the WM.
+
+> People tend to insist this should be a WM option, but that's just
+> busted, since GTK and apps also have Xinerama-awareness features.
+
+
+******************* EDID
+
+edid-decode enhancements:
+
+- Rejects years <= 0x0f for all versions, but this should only be done
+ for monitors claiming conformance to 1.4 (since 1.4 was released in
+ 2006). A monitor produced in 2005 should have 0x0f - it's the only
+ reasonable thing to do.
+
+- Uses 0x80 as the conformance mask for 1.4, should be 0
+
+- Should read from stdin
+
+- Should parse xrandr -verbose output more robustly
+
+- Color depth computation is wrong. It uses the formula
+
+ (edid[0x14] >> 3) + 2
+
+ The correct formula to use is
+
+ (edid[0x14] & 0x70) >> 3 + 4
+
+-
+
+-=-=-=-
+Computing a display name from EDID information:
+
+ vendor = lookup_vendor (code);
+
+ if (dsc_product && !is_gobbledigook (dsc_product))
+ {
+ if (vendor && !fuzzy_string_search (vendor, dsc_product))
+ prepend (vendor);
+ }
+ else
+ {
+ if (vendor)
+ append (vendor);
+ else
+ append ("Unknown");
+ }
+
+ if (has size)
+ {
+ convert_to_inches()
+
+ append (" %d\"", inches)
+ }
+
+(Does this internationalize at all)?
+
+We also need the ability to get laptop names. The laptop panel may report
+a manufacturer that has nothing to do with the laptop manufacturer.
+
+Needed XRandr output properties:
+
+- Modes that the monitor supports, or enough information that the
+ client can go throught the list of modes for the relevant
+ CRTC/Outputs and filter those out that the monitor can't support.
+
+- The preferred mode, if any. Also useful if we could get a "strongly
+ preferred" indication if it's an LCD with a fixed resolution.
+
+- Sufficient information that a fairly specific identifier can be
+ computed. The algorithm the client should use is:
+
+ 1 Have we seen exactly this monitor before? If yes, use
+ settings for that.
+
+ 2 Have we seen a monitor with similar specs before? If yes,
+ use settings for that. (But don't save, unless the user
+ changes the settings).
+
+ 3 Otherwise, use some reasonable default for the monitor and
+ save it.
+
+ A setting should only be used if the CRTC/Output allows it. Ie,. if
+ a user has installed a new video card, then previously-used settings
+ may no longer apply, so this must be checked every time.
+
+ (1) Implies that we really need a globally unique identifier for
+ monitors. (2) is useful in an enterprise setting, but not absolutely
+ critical, since (3) would still handle the majority of cases.
+
+ There is a question here: Where are machine specific preferences
+ stored? Havoc mentions three possibilities here:
+
+ http://mail.gnome.org/archives/matecc-list/2001-October/msg00023.html
+
+ I'm not sure if any of them are implementable at this point. Also
+ (1) may mostly take care of the problem.
+
+
+ Usecases:
+
+ 1. Fixed setup with some number of monitors.
+ - They should be set to the correct mode on login.
+ Note that this involves setting the right position in the
+ framebuffer too.
+
+ What if someone swaps two monitors? Users are going to expect
+ that the images will switch position.
+
+ 2. Laptop being moved between home and work
+ - Setups should be detected and the correct mode set, at least on
+ login, but ideally when you put the laptop into the docking
+ station.
+
+ 3. Laptop gets projector plugged in.
+
+ Note the same model monitor can be used in two different ways. Ie.,
+ at home, it's being used at one resolution, at work the same type of
+ monitor is used at a different resolution.
+
+ Simple solution:
+
+ - The on-disk database is just a list of monitors. Each monitor has an
+ associated mode. This has these problems:
+ - If someone uses the same monitor model in two different ways.
+ - If someone swaps the monitors around
+
+ Better solution
+
+ - The on-disk database is a list of configurations, where a
+ configuration is a list of monitors and what outputs they are
+ connected to, and the position in the framebuffer.
+
+ - Picking a default configuration is then a matter of selecting the
+ closest existing configuration from the database.
+
+ - If the stored configuration is a subset of the existing,
+ then use that - then pick the best mode available for the
+ rest of the monitors
+
+ - If the stored configuration is a superset of the existing,
+ then use the projection of the configuration onto the monitors.
+
+ - Pick the configuration with the most overlap in monitors.
+ Although, if a configuration differs only in what outputs
+ they are connected to, then those outputs should probably
+ get their original modes set.
+
+ - Or maybe simply:
+
+ - If there is an exact match, use it, if not, pick a default.
+
+ - Picking a new default must never change the mode of any existing
+ output.
+
+******************* Capplet
+
+Somehow the applet will find out that a new monitor is plugged in
+(either through notification, or through a refresh button). When this
+happens, this monitor is looked up in a database and if it is found,
+some suitable mode is set.
+
+Restrictions on the modes:
+
+- Monitors that are already plugged in should not get their mode
+ changed just because a new monitor is plugged in.
+
+- If the exact configuration of monitors is known, and all the old
+ monitors have the same mode as the known configuration, then just use
+ the known configuration. Also do this, if the configuration is a
+ subset of something known.
+
+- Otherwise, if the configuration is a subset of a known configuration
+ where the only difference is that existing monitors have different
+ modes, then try and convert that mode to something we can know
+ about. Maybe configurations should be stored in terms of edges that
+ line up.
+
+- Otherwise, just pick some good default for the mode, probably based
+ on the EDID prferred mode if possible. By default cloning is
+ probably best.
+
+- How do virtual desktops interact with this?
+
+
+g-s-d:
+
+- On startup
+
+ - It reads the configuration file into memory
+
+ capplet --configure
+
+ - It gathers the existing configuration from randr
+
+ - If the existing config is in the file, set that mode
+
+- On changes, including changes to the config file [this is crack]
+
+ - Reread configuration file
+
+ - Compare new configuration to database, if it is there, set the
+ mode as appropriate
+
+ - If a monitor was added, pop up a bubble
+
+ capplet --show-bubble
+
+ capplet --set-mode
+
+capplet
+
+- On changes
+
+ - Update GUI
+
+- When user changes something,
+
+ - Write configuration to file
+
+ - Signal gsd somehow
+
+Schemes:
+ - configuration file changes
+ - randr code will have to be shared between gcc and gsd
+
+ - binary installed by gcc
+ - something will still have to listen for changes to pop
+ up the notification bubble.
+
+Structure of capplet:
+
+- There is a database on disk with monitors and their corresponding
+ settings.
+
+- On startup, this database is read into memory. When the user accepts
+ new settings, it is written back to disk.
+
+- When something changes about the settings
+
+ - If new configuration is in the database, use that mode
+
+ - Else, find all outputs that are now connected but weren't before,
+ and set a default mode for them.
+
+ - If GUI is running, update graphics.
+
+
+ - Notification thing:
+ - if
+
+ - if the new configuration is found in the database, use it
+
+ and added if they are not already there. Initial settings are
+ 1 what the output is already doing, if anything
+ 2 based on an existing sufficiently similar monitor, if possible
+ 3 some reasonable default.
+
+- When the user changes settings in the GUI, the corresponding monitor
+ in the database is updated.
+
+- Whenever the GUI settings change, for all displayed monitors the
+ possible modes are recomputed.
+
+- Whenever a new monitor is selected in the GUI, it first gets all its
+ possible modes computed based on the selections on other
+ outputs. Then, if the possible modes include the existing choice of
+ resolution, that is selected.
+
+ Actually,
+
+ - initially, the settings are copied from the current settings
+
+ - whenever a gui setting changes for a monitor, all the other
+ monitors get their list of choices set to whatever is possible
+ given the chocie for the current monitor. A 'desired mode' is
+ maintained, and the closest choice to that is displayed. Whenever
+ the user actively selects something, that becomes the desired mode
+ for that monitor.
+
+- Required
+
+ - Generate all outputs that are newly connected
+
+ foreach_newly_connected (Configuration *before, Configuration *after,
+ OutputFunc);
+
+ - A way to generate the best mode for a connected output
+
+ existing best_mode() can probably be used
+
+ - Given a list of modes, pick the one closest to a given mode.
+
+ (a possibility here is: pick an exact match, if that's
+ impossible, then pick the best one with the same
+ width/height, if that's impossible, then just pick the
+ best mode on the list).
+
+ - For a configuation, fix the mode for a subset of the outputs, then
+ list the combinations for the rest of the outputs.
+
+ An obvious possibility here is to simply list all possibilities,
+ then weed out those that don't work. Is this too expensive?
+ It might be.
+
+Structure of login time program:
+
+- The configuration database is read
+
+- The current hardware configuration is generated
+
+- If the current configuration is found in the database, that mode is set.
+
+- If it isn't found, then nothing changes.
+
+ This could just be mate-screen-resolution-capplet --reset
+
+******************* Things that need to be done to the xrandr.patch:
+
+===
+
+XRRGetScreenResources() is a roundtrip and very slow (~0.5 s). GTK+
+needs to keep information up-to-date by tracking events rather than
+calling this function. In fact we probably can't call it at all unless
+its performance improves significantly.
+
+If EDID processing really has to be this slow, and we can't get
+interrupts when monitors are plugged in, then we have a problem,
+because we can't do anything this expensive once per second.
+
+
+Detailed notes (but most of the patch should be rewritten):
+
+
+=== FIXME in gdkscreen-x11.c in get_width_mm()
+
+/* monitor pixel width / screen pixel width * screen_physical width */
+
+
+
+=== Check for 1.2 library
+
+The patch should check that the 1.2 version of the XRandR library is
+available before using the functions. A possibility is to not use any
+RandR unless 1.2 is available, another is to conditionalize the code.
+
+The most sane thing is probably to just require 1.2.
+
+On the other hand, installing a newer gtk+ on a system with older X is
+probably not that unusual, so maybe it's better to do the full 1.0,
+vs. 1.1 vs 1.2 check.
+
+For now it just requires 1.2.
+
+Actually, this might be fine because the only place where we make use
+of a 1.1 library is in the _gdk_x11_screen_size_changed() function,
+but there we have a fallback that just updates the variables in the
+Screen struct itself.
+
+So, only defining HAVE_RANDR if we detect 1.2 should be ok.
+
+=== Monitor information available
+
+- Subpixel information. This should be set automatically for the fonts and
+ store under the name of the monitor. If the user changes the font
+ configuration, that change should also be stored under the monitor name.
+
+- When a monitor we don't know about is plugged in, a configuration should
+ be generated:
+
+ - Screen size, computed based on the location of the screens
+
+ - RGBA information
+
+ - Whether the screen has a panel on it
+
+ - If there is a conflict between stored information and EDID,
+ the stored information wins
+
+
+
+New API so far:
+
+(* monitors_changed) signal
+gdk_screen_get_monitor_width_mm()
+gdk_screen_get_monitor_height_mm()
+gdk_screen_get_monitor_name() => Note this is the output (eg. "DVI-0")
+
+We should probably also have
+get_manufacturer()
+get_serial()
+get_resolutions()
+
+etc.
+
+Should there be a GdkMonitor object that would correspond to an
+output? Or maybe GdkOutput?
+
+screen_list_monitors()
+
+
+*************************** Issues XRandR/Xserver
+
+- We need polling in the X server, whenever something changes, X must
+ recompute the information and cache it, then send an event. Note the
+ situation where the user disconnects and reconnects a monitor within
+ the polling interval. The event could missed in that case since the polling
+ cannot do a full EDID query. Difficult to see a way around this.
+
+ Actually, DDC allows random access, so it should be possible to just
+ read theq vendor id and manufacturer codes. This can be done once a
+ second without a problem. The polling should be turned off in power
+ saving mode anyway.
+
+ - Driver work:
+
+ - Intel driver:
+
+ - EDID information is not reported for VGA when the output is not
+ turned on (i945 laptop).
+
+ - Screen size must be dynamically changable. (No xorg.conf changes
+ should be required).
+
+ - Make use of ACPI information when possible.
+
+ Adam has code on his freedesktop page.
+
+ - i830 laptop can be put in a state where XRandr reports that no
+ outputs are connected to a CRTC, but the panel is on.
+
+ - Plug in VGA
+ - xrandr --auto
+ - xrandr --output VGA --off
+ - run chk
+ - xrandr --verbose will now not report any outputs as turned on
+ - run chk again - all screens will be turned off
+
+ - Small Sun monitor - an 1152x921 mode is generated, but the
+ monitor doesn't handle that. The monitor itself only claims to
+ handle 1152x920. It doesn't look to me like there is anything
+ in the EDID information that would indicate that it could handle
+ 1152x921.
+
+ This happens with a radeon as wellso it may be a bug in the
+ generic X server EDID parsing. The X server apparently
+ interpretes the standard timing 1152x920 as 1152x921.
+
+ This happens because the X server uses
+
+ hsize * 4 / 5
+
+ which gives 921 for 1152. By using
+
+ (hsize / 5) * 4
+
+ you get 920. The 66 Hz version can bet set, the 76 Hz mode gets
+ sync out of range. (Would be interesting to find out whether the
+ 1152x920 ModeLine would allow the 76 Hz version to be set).
+
+ This is for the ATI driver as shipped in F8:
+
+ - XRRGetScreenResources() takes half a second.
+
+ - Adam has now removed a workaround that caused some of the slowdown.
+
+ - If a DVI monitor is disconnected, you get "Unknown" for connection
+ status.
+
+ - If a VGA monitor is plugged in, then EDID information is not
+ available, even after running xrandr --verbose. The monitor has
+ to be plugged in at driver startup time, apparently.
+
+ - Logging out and logging back in often results in some random mode being
+ set. We need mode selection to not be completely screwed up.
+ Currently it is.
+
+ - The set up at server startup needs to be fixed. *If* randr actually works,
+ then we might be able to do something sensible.
+
+ - We need to revisit the idea that many monitors have broken EDID data.
+ This may be less widespread than previously believed.
+
+- It may be useful to return the connector names as identifiers instead
+ of relying on UTF-8 strings. Ie., have an enum
+
+ { UNKNOWN, OTHER, DVI, VGA, HDMI, ..., }
+
+ in addition to the string. The difference between UNKNOWN and OTHER is that
+ UNKNOWN means the driver doesn't know, whereas OTHER means it is something
+ not listed in the enum (which could be listed in a later version).
+
+- Mouse cursor should be confined to the visible area. (It is already, I think)
+
+- It looks like EDID information is only available for one output
+ even though it is actually read according to the log file.
+ (nv, intel drivers)
+
+
+*********************************
+
+
+
+DONE:
+
+Server work:
+
+ - i830 laptop incorrectly reports BadMatch when you configure the
+ CRTC to drive both VGA and LVDS with the 1024x768 mode that both
+ outputs can handle. (It should return 'failed' if it can't do
+ that). Same for i945 laptop. It seems as if the same CRTC can't
+ drive more than one output at the same time on Intel.
+
+ This was a client bug, but the documentation for SetCrtcConfig
+ should say that BadMatch will be returned if the outputs aren't
+ clones.
+
+GTK+ patch is in now.
+
+=== Add helper function
+
+
++ if (screen_x11->randr12)
++ {
++ XRRScreenResources *sr;
++ XRROutputInfo *output;
++ gchar *retval;
++
++ sr = XRRGetScreenResources ( screen_x11->xdisplay,
++ screen_x11->xroot_window );
++
++ output = XRRGetOutputInfo ( screen_x11->xdisplay,
++ sr,
++ (RROutput)screen_x11->act_outputs[monitor_num]
+);
+
+ Might be worthwhile to factor this out into a
+ gdk_screen_get_output_info (screen, monitor_num)
+ helper function ?
+
+Instead of cutting and pasting all over creation
+
+* Calling XRRGetScreenResources all the time is not going to fly. It
+ takes hundreds of milliseconds ... Even if it didn't, it wouldn't
+ be acceptable to do all those roundtrips.
+
+
+=== Some g_prints left
+
+
+=== Version check
+
+Should be (maj > 1) || (maj == 1 && min >= 2)
+
+
+=== Grep for TODO
+
+
+=== Setup XRRSelectInput()
+
+ You should call XRRSelectInput() at the same place where you are
+ calling XSelectInput() right now. The right place to handle the
+ XRandr events is the huge switch in gdkevents-x11.c:gdk_event_translate
+ Check out how other extension events are handled there, like
+ XKB, or XFixes.
+
+
+=== Lots of variable naming issues, such as act_output and noutput
+
+=== Needs to select the input, and hook it up to the signal
+
+=== Add version markers to API
+
+=== API to turn monitors on and off?
+
+- DPMS not exposed through randr, maybe should be
+
+ - DPMS is presumably a property of either an
+ output or a CRTC. Logically it's an output.
+
+- Need events when DPMS happens. Exposing the "screen saving on" on
+ dbus may not be good enough.
+
+=== Why does init_multihead_support() start by freeing monitors and
+outputs?
+
+=== Do we disable Xinerama support entirely when 1.2 is in use?
+
+=== We should expose information about what parts of the screen monitors
+are viewing.
+
+=== Make use of the EDID information?
+
+
+-- details for X server --
+
+In nv driver SorSetOutputProperty should return TRUE for unknown
+properties. (Like the Intel driver does).
+
+Detecting plugged in
+
+- Periodically poll
+ -
+
+ - One ddc probe takes 5 ms, according to a comment in the intel
+ driver. Running this twice a second would mean spending 1% of
+ overall time doing ddc polling, which is almost certainly not
+ acceptable.
+
+ 1) Async I2C:
+
+ void I2CProbeAsync(..., callback, data);
+ Bool I2CPending()
+ void I2CUpdate()
+
+ In Dispatch, call I2CUpdate()
+ Before going idle, do
+
+ while (I2CPending())
+ I2CUpdate()
+
+ Would need
+ RegisterDispatchFunction() (Is this called Wakeup?)
+ RegisterIdleFunction()
+
+ Note the idle function should have the option of saying:
+ "check if something else happened; if not, call me again" and
+ "ok, I'm done - go idle". Otherwise, we would be blocking for
+ 5 ms whenever the X server went idle. So actually the idle
+ function should be
+
+ if (I2CPending())
+ {
+ I2CUpdate();
+ return TRUE; /* call me again */
+ }
+ else
+ {
+ return FALSE; /* I'm done */
+ }
+
+ What happens if another I2C requests come in while an async one
+ is pending? Most likely we simply finish whatever is going on,
+ then process the new request.
+
+ What happens if an X request takes so long that we get timeouts on
+ the i2c bus? Good question. Need to read the VESA ddc spec.
+
+ 2) Run the polling in a separate thread.
+
+ Probably crack.
+
+ 3) Run the polling less, maybe once every three seconds.
+
+-- details for control panel --
+Screen changes
+ - Currently it is polling via rw_screen_refresh(), which will always emit
+ a screen-changed event. In reponse to this event the capplet currently
+ checks whether anything changed physically about the setup. This means
+ the capplet can't react to external changes to modes. On the other hand
+ if it didn't
+Disallow combinations that would exceed the screen ranges.
+ - Note rotations
+
+Give rw objects stable positions in memory so that they can be cached
+across screen_changed events.
+
+Add Clone Mode
+
+Drag and drop for the monitors
+ - 2 dimensional layout
+
+Store make and model in monitors.xml, then if serial numbers don't
+match, fall back to a make and model match. Users with an nfs mounted
+home directory should not have to reconfigure for each new system they
+log in to.
+
+Make sure text is scaled correctly
+
+Need to sanitize naming
+ RWOutput vs Output - should probably be OutputInfo
+ rate vs. freq - decide on one
+
+Should probably reconsider the use of null terminated arrays.
+Maybe lists would be better.
+
+Pick a fixed scale, so that two 1024x768 don't look like two 6x4.
+ - An alternative would be to draw a checkerboard pattern
+ below the monitors.
+
+
+
+done:
+
+Add rotation
+
+Disable panel checkbox for now
+
+Patch into mate-desktop
+
+Find out how to share code between gcc and gsd
+
+Make it assign coordinates correctly
+ - including computing correct screen size
+
diff --git a/capplets/display/display-capplet.ui b/capplets/display/display-capplet.ui
new file mode 100644
index 00000000..82ed92bd
--- /dev/null
+++ b/capplets/display/display-capplet.ui
@@ -0,0 +1,437 @@
+<?xml version="1.0"?>
+<interface>
+ <requires lib="gtk+" version="2.16"/>
+ <!-- interface-naming-policy toplevel-contextual -->
+ <object class="GtkDialog" id="dialog">
+ <property name="border_width">5</property>
+ <property name="title" translatable="yes">Monitor Preferences</property>
+ <property name="type_hint">dialog</property>
+ <property name="has_separator">False</property>
+ <child internal-child="vbox">
+ <object class="GtkVBox" id="dialog-vbox1">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child>
+ <object class="GtkTable" id="table2">
+ <property name="visible">True</property>
+ <property name="n_rows">2</property>
+ <property name="n_columns">2</property>
+ <property name="column_spacing">12</property>
+ <property name="row_spacing">12</property>
+ <child>
+ <object class="GtkVBox" id="vbox3">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GtkAlignment" id="align">
+ <property name="visible">True</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkHBox" id="hbox1">
+ <property name="visible">True</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GtkCheckButton" id="clone_checkbox">
+ <property name="label" translatable="yes">Sa_me image in all monitors</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="detect_displays_button">
+ <property name="label" translatable="yes">_Detect monitors</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_underline">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="pack_type">end</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkVBox" id="vbox4">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkLabel" id="label8">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Panel icon</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkAlignment" id="alignment2">
+ <property name="visible">True</property>
+ <property name="left_padding">12</property>
+ <child>
+ <object class="GtkCheckButton" id="show_notification_icon">
+ <property name="label" translatable="yes">_Show monitors in panel</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="right_attach">2</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkAlignment" id="alignment1">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="yalign">0</property>
+ <child>
+ <object class="GtkTable" id="table1">
+ <property name="visible">True</property>
+ <property name="n_rows">6</property>
+ <property name="n_columns">2</property>
+ <property name="column_spacing">12</property>
+ <property name="row_spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">_Resolution:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">resolution_combo</property>
+ </object>
+ <packing>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label3">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Re_fresh rate:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">refresh_combo</property>
+ </object>
+ <packing>
+ <property name="top_attach">3</property>
+ <property name="bottom_attach">4</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBox" id="resolution_combo">
+ <property name="visible">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBox" id="refresh_combo">
+ <property name="visible">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">3</property>
+ <property name="bottom_attach">4</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkHBox" id="hbox2">
+ <property name="visible">True</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GtkRadioButton" id="monitor_on_radio">
+ <property name="label" translatable="yes">On</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkRadioButton" id="monitor_off_radio">
+ <property name="label" translatable="yes">Off</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="draw_indicator">True</property>
+ <property name="group">monitor_on_radio</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="right_attach">2</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEventBox" id="current_monitor_event_box">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkLabel" id="current_monitor_label">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Monitor</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="right_attach">2</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label5">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">R_otation:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">rotation_combo</property>
+ </object>
+ <packing>
+ <property name="top_attach">4</property>
+ <property name="bottom_attach">5</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBox" id="rotation_combo">
+ <property name="visible">True</property>
+ <property name="model">liststore1</property>
+ <child>
+ <object class="GtkCellRendererText" id="cellrenderertext1"/>
+ <attributes>
+ <attribute name="text">0</attribute>
+ </attributes>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">4</property>
+ <property name="bottom_attach">5</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="panel_checkbox">
+ <property name="label" translatable="yes">Include _panel</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="top_attach">5</property>
+ <property name="bottom_attach">6</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkAlignment" id="alignment4">
+ <property name="visible">True</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">5</property>
+ <property name="bottom_attach">6</property>
+ <property name="x_options"></property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="x_options"></property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child internal-child="action_area">
+ <object class="GtkHButtonBox" id="dialog-action_area1">
+ <property name="visible">True</property>
+ <property name="layout_style">end</property>
+ <child>
+ <object class="GtkButton" id="helpbutton1">
+ <property name="label">gtk-help</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ <property name="secondary">True</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="make_default_button">
+ <property name="label" translatable="yes">Make Default</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_underline">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="apply_button">
+ <property name="label">gtk-apply</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button2">
+ <property name="label">gtk-close</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="-11">helpbutton1</action-widget>
+ <action-widget response="1">make_default_button</action-widget>
+ <action-widget response="-10">apply_button</action-widget>
+ <action-widget response="-7">button2</action-widget>
+ </action-widgets>
+ </object>
+ <object class="GtkListStore" id="liststore1">
+ <columns>
+ <!-- column-name item -->
+ <column type="gchararray"/>
+ </columns>
+ <data>
+ <row>
+ <col id="0" translatable="yes">Normal</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">Left</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">Right</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">Upside-down</col>
+ </row>
+ </data>
+ </object>
+</interface>
diff --git a/capplets/display/display-properties.desktop.in.in b/capplets/display/display-properties.desktop.in.in
new file mode 100644
index 00000000..bcfb5935
--- /dev/null
+++ b/capplets/display/display-properties.desktop.in.in
@@ -0,0 +1,14 @@
+[Desktop Entry]
+_Name=Monitors
+_Comment=Change resolution and position of monitors
+Exec=mate-display-properties
+Icon=mate-preferences-desktop-display
+Terminal=false
+Type=Application
+StartupNotify=true
+Categories=MATE;GTK;Settings;HardwareSettings;
+OnlyShowIn=MATE;
+X-MATE-Bugzilla-Bugzilla=MATE
+X-MATE-Bugzilla-Product=mate-control-center
+X-MATE-Bugzilla-Component=Screen resolution
+X-MATE-Bugzilla-Version=@VERSION@
diff --git a/capplets/display/foo-marshal.c b/capplets/display/foo-marshal.c
new file mode 100644
index 00000000..a40b0863
--- /dev/null
+++ b/capplets/display/foo-marshal.c
@@ -0,0 +1,279 @@
+
+#include <glib-object.h>
+
+
+#ifdef G_ENABLE_DEBUG
+#define g_marshal_value_peek_boolean(v) g_value_get_boolean (v)
+#define g_marshal_value_peek_char(v) g_value_get_char (v)
+#define g_marshal_value_peek_uchar(v) g_value_get_uchar (v)
+#define g_marshal_value_peek_int(v) g_value_get_int (v)
+#define g_marshal_value_peek_uint(v) g_value_get_uint (v)
+#define g_marshal_value_peek_long(v) g_value_get_long (v)
+#define g_marshal_value_peek_ulong(v) g_value_get_ulong (v)
+#define g_marshal_value_peek_int64(v) g_value_get_int64 (v)
+#define g_marshal_value_peek_uint64(v) g_value_get_uint64 (v)
+#define g_marshal_value_peek_enum(v) g_value_get_enum (v)
+#define g_marshal_value_peek_flags(v) g_value_get_flags (v)
+#define g_marshal_value_peek_float(v) g_value_get_float (v)
+#define g_marshal_value_peek_double(v) g_value_get_double (v)
+#define g_marshal_value_peek_string(v) (char*) g_value_get_string (v)
+#define g_marshal_value_peek_param(v) g_value_get_param (v)
+#define g_marshal_value_peek_boxed(v) g_value_get_boxed (v)
+#define g_marshal_value_peek_pointer(v) g_value_get_pointer (v)
+#define g_marshal_value_peek_object(v) g_value_get_object (v)
+#else /* !G_ENABLE_DEBUG */
+/* WARNING: This code accesses GValues directly, which is UNSUPPORTED API.
+ * Do not access GValues directly in your code. Instead, use the
+ * g_value_get_*() functions
+ */
+#define g_marshal_value_peek_boolean(v) (v)->data[0].v_int
+#define g_marshal_value_peek_char(v) (v)->data[0].v_int
+#define g_marshal_value_peek_uchar(v) (v)->data[0].v_uint
+#define g_marshal_value_peek_int(v) (v)->data[0].v_int
+#define g_marshal_value_peek_uint(v) (v)->data[0].v_uint
+#define g_marshal_value_peek_long(v) (v)->data[0].v_long
+#define g_marshal_value_peek_ulong(v) (v)->data[0].v_ulong
+#define g_marshal_value_peek_int64(v) (v)->data[0].v_int64
+#define g_marshal_value_peek_uint64(v) (v)->data[0].v_uint64
+#define g_marshal_value_peek_enum(v) (v)->data[0].v_long
+#define g_marshal_value_peek_flags(v) (v)->data[0].v_ulong
+#define g_marshal_value_peek_float(v) (v)->data[0].v_float
+#define g_marshal_value_peek_double(v) (v)->data[0].v_double
+#define g_marshal_value_peek_string(v) (v)->data[0].v_pointer
+#define g_marshal_value_peek_param(v) (v)->data[0].v_pointer
+#define g_marshal_value_peek_boxed(v) (v)->data[0].v_pointer
+#define g_marshal_value_peek_pointer(v) (v)->data[0].v_pointer
+#define g_marshal_value_peek_object(v) (v)->data[0].v_pointer
+#endif /* !G_ENABLE_DEBUG */
+
+
+/* VOID:OBJECT,OBJECT (marshal.list:1) */
+void
+foo_marshal_VOID__OBJECT_OBJECT (GClosure *closure,
+ GValue *return_value G_GNUC_UNUSED,
+ guint n_param_values,
+ const GValue *param_values,
+ gpointer invocation_hint G_GNUC_UNUSED,
+ gpointer marshal_data)
+{
+ typedef void (*GMarshalFunc_VOID__OBJECT_OBJECT) (gpointer data1,
+ gpointer arg_1,
+ gpointer arg_2,
+ gpointer data2);
+ register GMarshalFunc_VOID__OBJECT_OBJECT callback;
+ register GCClosure *cc = (GCClosure*) closure;
+ register gpointer data1, data2;
+
+ g_return_if_fail (n_param_values == 3);
+
+ if (G_CCLOSURE_SWAP_DATA (closure))
+ {
+ data1 = closure->data;
+ data2 = g_value_peek_pointer (param_values + 0);
+ }
+ else
+ {
+ data1 = g_value_peek_pointer (param_values + 0);
+ data2 = closure->data;
+ }
+ callback = (GMarshalFunc_VOID__OBJECT_OBJECT) (marshal_data ? marshal_data : cc->callback);
+
+ callback (data1,
+ g_marshal_value_peek_object (param_values + 1),
+ g_marshal_value_peek_object (param_values + 2),
+ data2);
+}
+
+/* VOID:UINT,UINT,UINT,UINT (marshal.list:2) */
+void
+foo_marshal_VOID__UINT_UINT_UINT_UINT (GClosure *closure,
+ GValue *return_value G_GNUC_UNUSED,
+ guint n_param_values,
+ const GValue *param_values,
+ gpointer invocation_hint G_GNUC_UNUSED,
+ gpointer marshal_data)
+{
+ typedef void (*GMarshalFunc_VOID__UINT_UINT_UINT_UINT) (gpointer data1,
+ guint arg_1,
+ guint arg_2,
+ guint arg_3,
+ guint arg_4,
+ gpointer data2);
+ register GMarshalFunc_VOID__UINT_UINT_UINT_UINT callback;
+ register GCClosure *cc = (GCClosure*) closure;
+ register gpointer data1, data2;
+
+ g_return_if_fail (n_param_values == 5);
+
+ if (G_CCLOSURE_SWAP_DATA (closure))
+ {
+ data1 = closure->data;
+ data2 = g_value_peek_pointer (param_values + 0);
+ }
+ else
+ {
+ data1 = g_value_peek_pointer (param_values + 0);
+ data2 = closure->data;
+ }
+ callback = (GMarshalFunc_VOID__UINT_UINT_UINT_UINT) (marshal_data ? marshal_data : cc->callback);
+
+ callback (data1,
+ g_marshal_value_peek_uint (param_values + 1),
+ g_marshal_value_peek_uint (param_values + 2),
+ g_marshal_value_peek_uint (param_values + 3),
+ g_marshal_value_peek_uint (param_values + 4),
+ data2);
+}
+
+/* VOID:UINT,UINT (marshal.list:3) */
+void
+foo_marshal_VOID__UINT_UINT (GClosure *closure,
+ GValue *return_value G_GNUC_UNUSED,
+ guint n_param_values,
+ const GValue *param_values,
+ gpointer invocation_hint G_GNUC_UNUSED,
+ gpointer marshal_data)
+{
+ typedef void (*GMarshalFunc_VOID__UINT_UINT) (gpointer data1,
+ guint arg_1,
+ guint arg_2,
+ gpointer data2);
+ register GMarshalFunc_VOID__UINT_UINT callback;
+ register GCClosure *cc = (GCClosure*) closure;
+ register gpointer data1, data2;
+
+ g_return_if_fail (n_param_values == 3);
+
+ if (G_CCLOSURE_SWAP_DATA (closure))
+ {
+ data1 = closure->data;
+ data2 = g_value_peek_pointer (param_values + 0);
+ }
+ else
+ {
+ data1 = g_value_peek_pointer (param_values + 0);
+ data2 = closure->data;
+ }
+ callback = (GMarshalFunc_VOID__UINT_UINT) (marshal_data ? marshal_data : cc->callback);
+
+ callback (data1,
+ g_marshal_value_peek_uint (param_values + 1),
+ g_marshal_value_peek_uint (param_values + 2),
+ data2);
+}
+
+/* VOID:BOXED (marshal.list:4) */
+
+/* VOID:BOXED,BOXED (marshal.list:5) */
+void
+foo_marshal_VOID__BOXED_BOXED (GClosure *closure,
+ GValue *return_value G_GNUC_UNUSED,
+ guint n_param_values,
+ const GValue *param_values,
+ gpointer invocation_hint G_GNUC_UNUSED,
+ gpointer marshal_data)
+{
+ typedef void (*GMarshalFunc_VOID__BOXED_BOXED) (gpointer data1,
+ gpointer arg_1,
+ gpointer arg_2,
+ gpointer data2);
+ register GMarshalFunc_VOID__BOXED_BOXED callback;
+ register GCClosure *cc = (GCClosure*) closure;
+ register gpointer data1, data2;
+
+ g_return_if_fail (n_param_values == 3);
+
+ if (G_CCLOSURE_SWAP_DATA (closure))
+ {
+ data1 = closure->data;
+ data2 = g_value_peek_pointer (param_values + 0);
+ }
+ else
+ {
+ data1 = g_value_peek_pointer (param_values + 0);
+ data2 = closure->data;
+ }
+ callback = (GMarshalFunc_VOID__BOXED_BOXED) (marshal_data ? marshal_data : cc->callback);
+
+ callback (data1,
+ g_marshal_value_peek_boxed (param_values + 1),
+ g_marshal_value_peek_boxed (param_values + 2),
+ data2);
+}
+
+/* VOID:POINTER,BOXED,POINTER (marshal.list:6) */
+void
+foo_marshal_VOID__POINTER_BOXED_POINTER (GClosure *closure,
+ GValue *return_value G_GNUC_UNUSED,
+ guint n_param_values,
+ const GValue *param_values,
+ gpointer invocation_hint G_GNUC_UNUSED,
+ gpointer marshal_data)
+{
+ typedef void (*GMarshalFunc_VOID__POINTER_BOXED_POINTER) (gpointer data1,
+ gpointer arg_1,
+ gpointer arg_2,
+ gpointer arg_3,
+ gpointer data2);
+ register GMarshalFunc_VOID__POINTER_BOXED_POINTER callback;
+ register GCClosure *cc = (GCClosure*) closure;
+ register gpointer data1, data2;
+
+ g_return_if_fail (n_param_values == 4);
+
+ if (G_CCLOSURE_SWAP_DATA (closure))
+ {
+ data1 = closure->data;
+ data2 = g_value_peek_pointer (param_values + 0);
+ }
+ else
+ {
+ data1 = g_value_peek_pointer (param_values + 0);
+ data2 = closure->data;
+ }
+ callback = (GMarshalFunc_VOID__POINTER_BOXED_POINTER) (marshal_data ? marshal_data : cc->callback);
+
+ callback (data1,
+ g_marshal_value_peek_pointer (param_values + 1),
+ g_marshal_value_peek_boxed (param_values + 2),
+ g_marshal_value_peek_pointer (param_values + 3),
+ data2);
+}
+
+/* VOID:POINTER,POINTER (marshal.list:7) */
+void
+foo_marshal_VOID__POINTER_POINTER (GClosure *closure,
+ GValue *return_value G_GNUC_UNUSED,
+ guint n_param_values,
+ const GValue *param_values,
+ gpointer invocation_hint G_GNUC_UNUSED,
+ gpointer marshal_data)
+{
+ typedef void (*GMarshalFunc_VOID__POINTER_POINTER) (gpointer data1,
+ gpointer arg_1,
+ gpointer arg_2,
+ gpointer data2);
+ register GMarshalFunc_VOID__POINTER_POINTER callback;
+ register GCClosure *cc = (GCClosure*) closure;
+ register gpointer data1, data2;
+
+ g_return_if_fail (n_param_values == 3);
+
+ if (G_CCLOSURE_SWAP_DATA (closure))
+ {
+ data1 = closure->data;
+ data2 = g_value_peek_pointer (param_values + 0);
+ }
+ else
+ {
+ data1 = g_value_peek_pointer (param_values + 0);
+ data2 = closure->data;
+ }
+ callback = (GMarshalFunc_VOID__POINTER_POINTER) (marshal_data ? marshal_data : cc->callback);
+
+ callback (data1,
+ g_marshal_value_peek_pointer (param_values + 1),
+ g_marshal_value_peek_pointer (param_values + 2),
+ data2);
+}
+
diff --git a/capplets/display/foo-marshal.h b/capplets/display/foo-marshal.h
new file mode 100644
index 00000000..4bef795d
--- /dev/null
+++ b/capplets/display/foo-marshal.h
@@ -0,0 +1,67 @@
+
+#ifndef __foo_marshal_MARSHAL_H__
+#define __foo_marshal_MARSHAL_H__
+
+#include <glib-object.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* VOID:OBJECT,OBJECT (marshal.list:1) */
+extern void foo_marshal_VOID__OBJECT_OBJECT (GClosure *closure,
+ GValue *return_value,
+ guint n_param_values,
+ const GValue *param_values,
+ gpointer invocation_hint,
+ gpointer marshal_data);
+
+/* VOID:UINT,UINT,UINT,UINT (marshal.list:2) */
+extern void foo_marshal_VOID__UINT_UINT_UINT_UINT (GClosure *closure,
+ GValue *return_value,
+ guint n_param_values,
+ const GValue *param_values,
+ gpointer invocation_hint,
+ gpointer marshal_data);
+
+/* VOID:UINT,UINT (marshal.list:3) */
+extern void foo_marshal_VOID__UINT_UINT (GClosure *closure,
+ GValue *return_value,
+ guint n_param_values,
+ const GValue *param_values,
+ gpointer invocation_hint,
+ gpointer marshal_data);
+
+/* VOID:BOXED (marshal.list:4) */
+#define foo_marshal_VOID__BOXED g_cclosure_marshal_VOID__BOXED
+
+/* VOID:BOXED,BOXED (marshal.list:5) */
+extern void foo_marshal_VOID__BOXED_BOXED (GClosure *closure,
+ GValue *return_value,
+ guint n_param_values,
+ const GValue *param_values,
+ gpointer invocation_hint,
+ gpointer marshal_data);
+
+/* VOID:POINTER,BOXED,POINTER (marshal.list:6) */
+extern void foo_marshal_VOID__POINTER_BOXED_POINTER (GClosure *closure,
+ GValue *return_value,
+ guint n_param_values,
+ const GValue *param_values,
+ gpointer invocation_hint,
+ gpointer marshal_data);
+
+/* VOID:POINTER,POINTER (marshal.list:7) */
+extern void foo_marshal_VOID__POINTER_POINTER (GClosure *closure,
+ GValue *return_value,
+ guint n_param_values,
+ const GValue *param_values,
+ gpointer invocation_hint,
+ gpointer marshal_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __foo_marshal_MARSHAL_H__ */
+
diff --git a/capplets/display/icons/16x16/mate-preferences-desktop-display.png b/capplets/display/icons/16x16/mate-preferences-desktop-display.png
new file mode 100644
index 00000000..f996ddf5
--- /dev/null
+++ b/capplets/display/icons/16x16/mate-preferences-desktop-display.png
Binary files differ
diff --git a/capplets/display/icons/22x22/mate-preferences-desktop-display.png b/capplets/display/icons/22x22/mate-preferences-desktop-display.png
new file mode 100644
index 00000000..cc47eec6
--- /dev/null
+++ b/capplets/display/icons/22x22/mate-preferences-desktop-display.png
Binary files differ
diff --git a/capplets/display/icons/24x24/mate-preferences-desktop-display.png b/capplets/display/icons/24x24/mate-preferences-desktop-display.png
new file mode 100644
index 00000000..49b4e12c
--- /dev/null
+++ b/capplets/display/icons/24x24/mate-preferences-desktop-display.png
Binary files differ
diff --git a/capplets/display/icons/32x32/mate-preferences-desktop-display.png b/capplets/display/icons/32x32/mate-preferences-desktop-display.png
new file mode 100644
index 00000000..95de3eaa
--- /dev/null
+++ b/capplets/display/icons/32x32/mate-preferences-desktop-display.png
Binary files differ
diff --git a/capplets/display/icons/scalable/mate-preferences-desktop-display.svg b/capplets/display/icons/scalable/mate-preferences-desktop-display.svg
new file mode 100644
index 00000000..0679b6b3
--- /dev/null
+++ b/capplets/display/icons/scalable/mate-preferences-desktop-display.svg
@@ -0,0 +1,470 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://web.resource.org/cc/"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="48.000000px"
+ height="48.000000px"
+ id="svg3304"
+ sodipodi:version="0.32"
+ inkscape:version="0.44+devel"
+ sodipodi:docbase="/home/jimmac/gfx/ximian/art/icons/control-center/scalable"
+ sodipodi:docname="change-resolution.svg"
+ inkscape:output_extension="org.inkscape.output.svg.inkscape"
+ sodipodi:modified="true">
+ <defs
+ id="defs3306">
+ <linearGradient
+ id="linearGradient2804">
+ <stop
+ style="stop-color:black;stop-opacity:0;"
+ offset="0"
+ id="stop2806" />
+ <stop
+ id="stop2812"
+ offset="0.5"
+ style="stop-color:black;stop-opacity:1;" />
+ <stop
+ style="stop-color:black;stop-opacity:0;"
+ offset="1"
+ id="stop2808" />
+ </linearGradient>
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient2804"
+ id="linearGradient2831"
+ gradientUnits="userSpaceOnUse"
+ x1="21.875"
+ y1="48.000977"
+ x2="21.875"
+ y2="40" />
+ <radialGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient2781"
+ id="radialGradient2829"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(2,0,0,0.8,36,8.8)"
+ cx="1"
+ cy="44"
+ fx="1"
+ fy="44"
+ r="5" />
+ <linearGradient
+ inkscape:collect="always"
+ id="linearGradient2781">
+ <stop
+ style="stop-color:black;stop-opacity:1;"
+ offset="0"
+ id="stop2783" />
+ <stop
+ style="stop-color:black;stop-opacity:0;"
+ offset="1"
+ id="stop2785" />
+ </linearGradient>
+ <radialGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient2781"
+ id="radialGradient2827"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(2,0,0,0.8,-13,-79.2)"
+ cx="1"
+ cy="44"
+ fx="1"
+ fy="44"
+ r="5" />
+ <linearGradient
+ id="linearGradient5137">
+ <stop
+ style="stop-color:#eeeeec;stop-opacity:1;"
+ offset="0"
+ id="stop5139" />
+ <stop
+ style="stop-color:#e6e6e3;stop-opacity:1;"
+ offset="1"
+ id="stop5141" />
+ </linearGradient>
+ <linearGradient
+ inkscape:collect="always"
+ id="linearGradient6240">
+ <stop
+ style="stop-color:#ffffff;stop-opacity:1;"
+ offset="0"
+ id="stop6242" />
+ <stop
+ style="stop-color:#ffffff;stop-opacity:0;"
+ offset="1"
+ id="stop6244" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient11400">
+ <stop
+ style="stop-color:#000000;stop-opacity:1;"
+ offset="0"
+ id="stop11402" />
+ <stop
+ style="stop-color:#000000;stop-opacity:0;"
+ offset="1"
+ id="stop11404" />
+ </linearGradient>
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient11400"
+ id="linearGradient11406"
+ x1="23.154902"
+ y1="34.572548"
+ x2="23.529411"
+ y2="40.219608"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="translate(0,0.7954955)" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient5137"
+ id="linearGradient5147"
+ gradientUnits="userSpaceOnUse"
+ x1="17.247635"
+ y1="6.3760414"
+ x2="39.904388"
+ y2="38.876041"
+ gradientTransform="translate(0,0.7954955)" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient5137"
+ id="linearGradient5223"
+ gradientUnits="userSpaceOnUse"
+ x1="31.743324"
+ y1="37.842293"
+ x2="31.86105"
+ y2="43.82579"
+ gradientTransform="translate(0,0.7954955)" />
+ <linearGradient
+ id="linearGradient7025"
+ inkscape:collect="always">
+ <stop
+ id="stop7027"
+ offset="0"
+ style="stop-color:#e6ce46;stop-opacity:1" />
+ <stop
+ id="stop7029"
+ offset="1"
+ style="stop-color:#d6ba1c;stop-opacity:1" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient22122"
+ inkscape:collect="always">
+ <stop
+ id="stop22124"
+ offset="0"
+ style="stop-color:black;stop-opacity:1;" />
+ <stop
+ id="stop22126"
+ offset="1"
+ style="stop-color:black;stop-opacity:0;" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient22140">
+ <stop
+ id="stop22142"
+ offset="0"
+ style="stop-color:black;stop-opacity:0;" />
+ <stop
+ style="stop-color:black;stop-opacity:1;"
+ offset="0.5"
+ id="stop22148" />
+ <stop
+ id="stop22144"
+ offset="1"
+ style="stop-color:black;stop-opacity:0;" />
+ </linearGradient>
+ <radialGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient22122"
+ id="radialGradient4770"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0,-1.000001,1.142856,0,-41.10259,45.50001)"
+ cx="7"
+ cy="39.464806"
+ fx="7"
+ fy="39.464806"
+ r="3.5" />
+ <radialGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient22122"
+ id="radialGradient4772"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0,-1.000001,1.142856,0,-89.10259,-31.49999)"
+ cx="7"
+ cy="39.464806"
+ fx="7"
+ fy="39.464806"
+ r="3.5" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient22140"
+ id="linearGradient4774"
+ gradientUnits="userSpaceOnUse"
+ x1="18.142136"
+ y1="35"
+ x2="18.142136"
+ y2="42.040661" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient7025"
+ id="linearGradient4776"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="translate(53,1.428571)"
+ x1="13.630114"
+ y1="28.5"
+ x2="25.208096"
+ y2="41.180992" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient6240"
+ id="linearGradient4778"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="translate(7.843e-3,0.7954955)"
+ x1="20.156862"
+ y1="5.0996137"
+ x2="20.156862"
+ y2="26.039215" />
+ </defs>
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#849193"
+ borderopacity="1.0000000"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="1"
+ inkscape:cx="39.697787"
+ inkscape:cy="26.598514"
+ inkscape:current-layer="layer1"
+ showgrid="false"
+ inkscape:grid-bbox="true"
+ inkscape:document-units="px"
+ inkscape:showpageshadow="false"
+ showborder="true"
+ inkscape:window-width="923"
+ inkscape:window-height="937"
+ inkscape:window-x="2004"
+ inkscape:window-y="169"
+ showguides="true"
+ inkscape:guide-bbox="true"
+ inkscape:grid-points="true" />
+ <metadata
+ id="metadata3309">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title>Change Resolution</dc:title>
+ <dc:creator>
+ <cc:Agent>
+ <dc:title>Jakub Steiner</dc:title>
+ </cc:Agent>
+ </dc:creator>
+ <cc:license
+ rdf:resource="http://creativecommons.org/licenses/GPL/2.0/" />
+ <dc:subject>
+ <rdf:Bag>
+ <rdf:li>display</rdf:li>
+ <rdf:li>resolution</rdf:li>
+ <rdf:li>video</rdf:li>
+ </rdf:Bag>
+ </dc:subject>
+ <dc:contributor>
+ <cc:Agent>
+ <dc:title>Andreas Nilsson
+Luca Ferretti &lt;[email protected]&gt;</dc:title>
+ </cc:Agent>
+ </dc:contributor>
+ <dc:date></dc:date>
+ <dc:source>http://www.gnome.org</dc:source>
+ </cc:Work>
+ <cc:License
+ rdf:about="http://creativecommons.org/licenses/GPL/2.0/">
+ <cc:permits
+ rdf:resource="http://web.resource.org/cc/Reproduction" />
+ <cc:permits
+ rdf:resource="http://web.resource.org/cc/Distribution" />
+ <cc:requires
+ rdf:resource="http://web.resource.org/cc/Notice" />
+ <cc:permits
+ rdf:resource="http://web.resource.org/cc/DerivativeWorks" />
+ <cc:requires
+ rdf:resource="http://web.resource.org/cc/ShareAlike" />
+ <cc:requires
+ rdf:resource="http://web.resource.org/cc/SourceCode" />
+ </cc:License>
+ </rdf:RDF>
+ </metadata>
+ <g
+ id="layer1"
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer">
+ <g
+ id="g2822"
+ style="opacity:0.3"
+ transform="matrix(0.9308511,0,0,1.037397,1.6941489,-1.795056)">
+ <rect
+ transform="scale(-1,-1)"
+ y="-48"
+ x="-11"
+ height="8"
+ width="10"
+ id="rect1892"
+ style="opacity:1;color:#000000;fill:url(#radialGradient2827);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:square;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:1.20000057;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" />
+ <rect
+ y="40"
+ x="38"
+ height="8"
+ width="10"
+ id="rect2789"
+ style="opacity:1;color:#000000;fill:url(#radialGradient2829);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:square;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:1.20000057;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" />
+ <rect
+ y="40"
+ x="11"
+ height="8"
+ width="27"
+ id="rect2793"
+ style="opacity:1;color:#000000;fill:url(#linearGradient2831);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:square;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:1.20000057;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" />
+ </g>
+ <rect
+ style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ id="rect4784"
+ width="48"
+ height="48"
+ x="0"
+ y="0.79549509" />
+ <path
+ style="opacity:1;color:#000000;fill:url(#linearGradient5223);fill-opacity:1;fill-rule:evenodd;stroke:#888a85;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible"
+ d="M 14.375479,36.328843 C 14.375479,36.328843 15.592355,41.263443 10.51915,41.309767 C 8.0888743,41.331672 8.5866723,45.344918 8.5866723,45.344918 L 39.433139,45.313545 C 39.433139,45.313545 39.851577,41.418182 37.410922,41.372513 C 32.423455,41.280374 33.600393,36.266098 33.600393,36.266098 L 14.375479,36.328843 z "
+ id="path9222"
+ sodipodi:nodetypes="csccscc" />
+ <path
+ style="fill:url(#linearGradient5147);fill-opacity:1;fill-rule:evenodd;stroke:#888a85;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1"
+ d="M 4.8886262,4.2739318 L 43.01746,4.2739318 C 45.042579,4.2739318 46.518438,5.7015863 46.518438,7.9000726 L 46.529388,34.103908 C 46.529388,35.795975 46.001041,36.319137 44.494732,36.319137 L 3.5320635,36.300202 C 2.3527922,36.271409 1.513468,35.805541 1.4976345,34.280899 L 1.5128113,7.7123281 C 1.5128113,5.9385022 3.0522187,4.2739318 4.8886262,4.2739318 z "
+ id="rect5040"
+ sodipodi:nodetypes="ccccccccc" />
+ <rect
+ style="fill:#555753;fill-opacity:1;fill-rule:evenodd;stroke:#2e3436;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ id="rect9208"
+ width="37.00032"
+ height="22.996691"
+ x="5.5059438"
+ y="8.2973185" />
+ <path
+ sodipodi:type="inkscape:offset"
+ inkscape:radius="-0.875"
+ inkscape:original="M 4.875 4.28125 C 3.0385925 4.28125 1.5 5.9449242 1.5 7.71875 L 1.5 34.28125 C 1.5158335 35.805892 2.3519787 36.283708 3.53125 36.3125 L 44.5 36.3125 C 46.006309 36.3125 46.53125 35.785816 46.53125 34.09375 L 46.53125 7.90625 C 46.53125 5.7077637 45.056369 4.2812498 43.03125 4.28125 L 4.875 4.28125 z "
+ xlink:href="#rect5040"
+ style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#ffffff;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1"
+ id="path5145"
+ inkscape:href="#rect5040"
+ d="M 4.875,5.0625 C 3.5670573,5.0625 2.375,6.3571498 2.375,7.625 L 2.375,34.1875 C 2.3812657,34.79084 2.515801,34.970853 2.65625,35.09375 C 2.796699,35.216647 3.0858905,35.332113 3.5625,35.34375 L 44.5,35.34375 C 45.151173,35.34375 45.356981,35.24273 45.4375,35.15625 C 45.518019,35.06977 45.65625,34.755549 45.65625,34 L 45.65625,7.8125 C 45.65625,6.0053499 44.645463,5.0624999 43.03125,5.0625 L 4.875,5.0625 z " />
+ <path
+ style="opacity:0.6;fill:url(#linearGradient11406);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ d="M 13.992156,36.834708 C 14.075817,39.007257 13.708803,39.746151 12.358532,40.509939 L 35.973934,41.807257 C 35.024915,40.638629 33.644523,38.873923 34.020993,36.819022 L 13.992156,36.834708 z "
+ id="path10672"
+ sodipodi:nodetypes="ccccc" />
+ <path
+ style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#8d8d8f;stroke-width:1px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:0.43902438"
+ d="M 9.9921262,42.291555 C 16.698819,42.293524 37.78891,42.291555 37.78891,42.291555"
+ id="path6575"
+ sodipodi:nodetypes="cc" />
+ <path
+ sodipodi:nodetypes="cc"
+ id="path8029"
+ d="M 9.647928,43.299429 C 16.354621,43.301398 38.367789,43.299429 38.367789,43.299429"
+ style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#ffffff;stroke-width:1px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1" />
+ <path
+ style="opacity:0.4;fill:url(#linearGradient4778);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ d="M 6.031372,8.8268676 L 6.031372,26.834708 C 22.475817,25.480459 28.630065,16.722289 41.999999,15.807256 L 42,8.7954956 L 6.031372,8.8268676 z "
+ id="path4073"
+ sodipodi:nodetypes="ccccc" />
+ <g
+ id="g4754"
+ transform="translate(-46.77135,-7.3370294)">
+ <g
+ transform="matrix(0.916667,0,0,0.714282,49.771334,11.132681)"
+ style="opacity:0.3"
+ id="g22150">
+ <rect
+ style="opacity:1;fill:url(#radialGradient4770);fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:10;stroke-dasharray:none;stroke-dashoffset:1.20000057;stroke-opacity:1"
+ id="rect22120"
+ width="4"
+ height="7"
+ x="0"
+ y="35" />
+ <rect
+ style="opacity:1;fill:url(#radialGradient4772);fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:10;stroke-dasharray:none;stroke-dashoffset:1.20000057;stroke-opacity:1"
+ id="rect22134"
+ width="4"
+ height="7"
+ x="-48"
+ y="-42"
+ transform="scale(-1,-1)" />
+ <rect
+ style="opacity:1;fill:url(#linearGradient4774);fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:10;stroke-dasharray:none;stroke-dashoffset:1.20000057;stroke-opacity:1"
+ id="rect22138"
+ width="40"
+ height="7"
+ x="4"
+ y="35" />
+ </g>
+ <g
+ id="g4743">
+ <g
+ id="g10824"
+ transform="translate(-5.228666,-6.29601)">
+ <path
+ id="path4319"
+ d="M 57.5,14.928571 L 57.5,44.928571 L 96.5,44.928571 L 57.5,14.928571 z M 63.5,27.928571 L 78.5,38.928571 L 63.5,38.928571 L 63.5,27.928571 z "
+ style="fill:url(#linearGradient4776);fill-opacity:1;fill-rule:evenodd;stroke:#a38503;stroke-width:1.00000024px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+ <path
+ sodipodi:nodetypes="cc"
+ id="path4326"
+ d="M 61.5,44.928571 L 61.5,41.928571"
+ style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:#a38503;stroke-width:1px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1" />
+ <path
+ sodipodi:nodetypes="cc"
+ id="path4328"
+ d="M 67.5,44.928571 L 67.5,41.928571"
+ style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:#a38503;stroke-width:1px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1" />
+ <path
+ sodipodi:nodetypes="cc"
+ id="path4330"
+ d="M 73.5,44.928571 L 73.5,41.964285"
+ style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:#a38503;stroke-width:1px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1" />
+ <path
+ sodipodi:nodetypes="cc"
+ id="path4332"
+ d="M 79.5,44.928571 L 79.5,41.928571"
+ style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:#a38503;stroke-width:1px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1" />
+ <path
+ sodipodi:nodetypes="cc"
+ id="path4334"
+ d="M 85.5,44.928571 L 85.5,41.928571"
+ style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:#a38503;stroke-width:1px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1" />
+ <path
+ id="path6126"
+ d="M 58.500002,16.928575 L 58.500002,43.928586 L 93.500014,43.928586 L 58.500002,16.928575 z "
+ style="opacity:0.4;fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:#ffffff;stroke-width:1.0000006px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+ </g>
+ <path
+ style="opacity:0.4;fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:#ffffff;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ d="M 9.5017474,38.542446 L 9.4575532,24.532894 L 28.541592,38.563262 L 9.5017474,38.542446 z "
+ id="path12221"
+ sodipodi:nodetypes="cccc"
+ transform="translate(47.771334,-4.867439)" />
+ </g>
+ </g>
+ </g>
+</svg>
diff --git a/capplets/display/mate-display-properties-install-systemwide.c b/capplets/display/mate-display-properties-install-systemwide.c
new file mode 100644
index 00000000..2d074eb8
--- /dev/null
+++ b/capplets/display/mate-display-properties-install-systemwide.c
@@ -0,0 +1,272 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * mate-display-properties-install-systemwide - Install a RANDR profile for the whole system
+ *
+ * Copyright (C) 2010 Novell, Inc.
+ *
+ * Authors: Federico Mena Quintero <[email protected]>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <errno.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <glib/gi18n.h>
+#include <glib.h>
+
+#define SYSTEM_RANDR_PATH "/etc/mate-settings-daemon/xrandr"
+
+static void
+usage (const char *program_name)
+{
+ g_print (_("Usage: %s SOURCE_FILE DEST_NAME\n"
+ "\n"
+ "This program installs a RANDR profile for multi-monitor setups into\n"
+ "a systemwide location. The resulting profile will get used when\n"
+ "the RANDR plug-in gets run in mate-settings-daemon.\n"
+ "\n"
+ "SOURCE_FILE - a full pathname, typically /home/username/.config/monitors.xml\n"
+ "\n"
+ "DEST_NAME - relative name for the installed file. This will get put in\n"
+ " the systemwide directory for RANDR configurations,\n"
+ " so the result will typically be %s/DEST_NAME\n"),
+ program_name,
+ SYSTEM_RANDR_PATH);
+}
+
+static gboolean
+is_basename (const char *filename)
+{
+ if (*filename == '\0')
+ return FALSE; /* no empty strings, please */
+
+ for (; *filename; filename++)
+ if (G_IS_DIR_SEPARATOR (*filename))
+ return FALSE;
+
+ return TRUE;
+}
+
+static gboolean
+copy_file (int source_fd, int dest_fd)
+{
+ char buf[1024];
+ int num_read;
+ int num_written;
+
+ while (TRUE) {
+ char *p;
+
+ num_read = read (source_fd, buf, sizeof (buf));
+ if (num_read == 0)
+ break;
+
+ if (num_read == -1) {
+ if (errno == EINTR)
+ continue;
+ else
+ return FALSE;
+ }
+
+ p = buf;
+ while (num_read > 0) {
+ num_written = write (dest_fd, p, num_read);
+ if (num_written == -1) {
+ if (errno == EINTR)
+ continue;
+ else
+ return FALSE;
+ }
+
+ num_read -= num_written;
+ p += num_written;
+ }
+ }
+
+ return TRUE;
+}
+
+/* This is essentially a "please copy a file to a privileged location" program.
+ * We try to be paranoid in the following ways:
+ *
+ * - We copy only regular files, owned by the user who called pkexec(1), to
+ * avoid attacks like "copy a file that I'm not allowed to read into a
+ * world-readable location".
+ *
+ * - We copy only to a well-known directory.
+ *
+ * - We try to avoid race conditions. We only fstat() files that we have open
+ * to avoid files moving under our feet. We only create files in directories
+ * that we have open.
+ *
+ * - We replace the destination file atomically.
+ */
+
+int
+main (int argc, char **argv)
+{
+ uid_t uid, euid;
+ const char *source_filename;
+ const char *dest_name;
+ const char *pkexec_uid_str;
+ int pkexec_uid;
+ struct stat statbuf;
+ int err;
+ int source_fd;
+ int dest_fd;
+ char template[100];
+
+ setlocale (LC_ALL, "");
+ bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ textdomain (GETTEXT_PACKAGE);
+
+ /* We only run as root */
+ uid = getuid ();
+ euid = geteuid ();
+ if (uid != 0 || euid != 0) {
+ /* Translators: only able to install RANDR profiles as root */
+ g_print ("%s\n", _("This program can only be used by the root user"));
+ return EXIT_FAILURE;
+ }
+
+ /* Usage: gsd-xrandr-install-systemwide SOURCE_FILE DEST_NAME */
+
+ if (argc != 3) {
+ usage (argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ source_filename = argv[1];
+ dest_name = argv[2];
+
+ /* Absolute source filenames only, please */
+
+ if (!g_path_is_absolute (source_filename)) {
+ g_print ("%s\n", _("The source filename must be absolute"));
+ return EXIT_FAILURE;
+ }
+
+ /* We only copy regular files */
+
+ source_fd = open (source_filename, O_RDONLY);
+ if (source_fd == -1) {
+ err = errno;
+
+ /* Translators: first %s is a filename; second %s is an error message */
+ g_print (_("Could not open %s: %s\n"),
+ source_filename,
+ g_strerror (err));
+ return EXIT_FAILURE;
+ }
+
+ if (fstat (source_fd, &statbuf) != 0) {
+ err = errno;
+ /* Translators: first %s is a filename; second %s is an error message */
+ g_print (_("Could not get information for %s: %s\n"),
+ source_filename,
+ g_strerror (err));
+ return EXIT_FAILURE;
+ }
+
+ if (!S_ISREG (statbuf.st_mode)) {
+ g_print (_("%s must be a regular file\n"),
+ source_filename);
+ return EXIT_FAILURE;
+ }
+
+ /* We only copy files that are really owned by the calling user */
+
+ pkexec_uid_str = g_getenv ("PKEXEC_UID");
+ if (pkexec_uid_str == NULL) {
+ g_print ("%s\n", _("This program must only be run through pkexec(1)"));
+ return EXIT_FAILURE;
+ }
+
+ if (sscanf (pkexec_uid_str, "%d", &pkexec_uid) != 1) {
+ g_print ("%s\n", _("PKEXEC_UID must be set to an integer value"));
+ return EXIT_FAILURE;
+ }
+
+ if (statbuf.st_uid != pkexec_uid) {
+ /* Translators: we are complaining that a file must be really owned by the user who called this program */
+ g_print (_("%s must be owned by you\n"), source_filename);
+ return EXIT_FAILURE;
+ }
+
+ /* We only accept basenames for the destination */
+
+ if (!is_basename (dest_name)) {
+ /* Translators: here we are saying that a plain filename must look like "filename", not like "some_dir/filename" */
+ g_print (_("%s must not have any directory components\n"),
+ dest_name);
+ return EXIT_FAILURE;
+ }
+
+ /* Chdir to the destination directory to keep it open... */
+
+ if (chdir (SYSTEM_RANDR_PATH) != 0) {
+ g_print (_("%s must be a directory\n"), SYSTEM_RANDR_PATH);
+ return EXIT_FAILURE;
+ }
+
+ /* ... and open our temporary destination file right there */
+
+ strcpy (template, "gsd-XXXXXX");
+ dest_fd = g_mkstemp_full (template, O_WRONLY, 0644);
+ if (dest_fd == -1) {
+ err = errno;
+ /* Translators: the first %s/%s is a directory/filename; the last %s is an error message */
+ g_print (_("Could not open %s/%s: %s\n"),
+ SYSTEM_RANDR_PATH,
+ template,
+ g_strerror (err));
+ return EXIT_FAILURE;
+ }
+
+ /* Do the copy */
+
+ if (!copy_file (source_fd, dest_fd)) {
+ /* If something went wrong, remove the destination file to avoid leaving trash around */
+ unlink (template);
+ return EXIT_FAILURE;
+ }
+
+ /* Rename to the final filename */
+
+ if (rename (template, dest_name) != 0) {
+ err = errno;
+ unlink (template);
+ g_print (_("Could not rename %s to %s: %s\n"),
+ template,
+ dest_name,
+ g_strerror (err));
+ return EXIT_FAILURE;
+ }
+
+ /* Whew! We'll leave the final closing of the files to the almighty kernel. */
+
+ return EXIT_SUCCESS;
+}
diff --git a/capplets/display/org.mate.randr.policy.in b/capplets/display/org.mate.randr.policy.in
new file mode 100644
index 00000000..6e9f65d2
--- /dev/null
+++ b/capplets/display/org.mate.randr.policy.in
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE policyconfig PUBLIC
+ "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
+<policyconfig>
+
+ <!--
+ Policy definitions for MATE's system-wide configuration of RANDR options
+ Copyright (c) 2010 Novell, Inc.
+ -->
+
+ <vendor>MATE Monitor Preferences</vendor>
+ <vendor_url>http://live.gnome.org/RandR</vendor_url>
+ <icon_name>mate-display-properties</icon_name>
+
+ <action id="org.mate.randr.install-system-wide">
+ <_description>Install multi-monitor settings for the whole system</_description>
+ <_message>Authentication is required to install multi-monitor settings for all users</_message>
+ <icon_name>mate-display-properties</icon_name>
+ <defaults>
+ <allow_any>no</allow_any>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>auth_admin_keep</allow_active>
+ </defaults>
+ <annotate key="org.freedesktop.policykit.exec.path">/usr/sbin/mate-display-properties-install-systemwide</annotate>
+ </action>
+
+</policyconfig>
+
diff --git a/capplets/display/scrollarea.c b/capplets/display/scrollarea.c
new file mode 100644
index 00000000..9da2fb66
--- /dev/null
+++ b/capplets/display/scrollarea.c
@@ -0,0 +1,1944 @@
+/* Copyright 2006, 2007, 2008, Soren Sandmann <[email protected]>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <gdk/gdkprivate.h> /* For GDK_PARENT_RELATIVE_BG */
+#include "scrollarea.h"
+#include "foo-marshal.h"
+
+G_DEFINE_TYPE (FooScrollArea, foo_scroll_area, GTK_TYPE_CONTAINER);
+
+static GtkWidgetClass *parent_class;
+
+typedef struct BackingStore BackingStore;
+
+typedef void (* ExposeFunc) (cairo_t *cr, GdkRegion *region, gpointer data);
+
+#if 0
+static void backing_store_draw (BackingStore *store,
+ GdkDrawable *dest,
+ GdkRegion *clip,
+ int dest_x,
+ int dest_y);
+static void backing_store_scroll (BackingStore *store,
+ int dx, int dy);
+static void backing_store_invalidate_rect (BackingStore *store,
+ GdkRectangle *rect);
+static void backing_store_invalidate_region (BackingStore *store,
+ GdkRegion *region);
+static void backing_store_invalidate_all (BackingStore *store);
+static BackingStore *backing_store_new (GdkWindow *window,
+ int width, int height);
+static void backing_store_resize (BackingStore *store,
+ int width, int height);
+static void backing_store_process_updates (BackingStore *store,
+ ExposeFunc func,
+ gpointer data);
+static void backing_store_free (BackingStore *store);
+#endif
+
+typedef struct InputPath InputPath;
+typedef struct InputRegion InputRegion;
+typedef struct AutoScrollInfo AutoScrollInfo;
+
+struct InputPath
+{
+ gboolean is_stroke;
+ cairo_fill_rule_t fill_rule;
+ double line_width;
+ cairo_path_t *path; /* In canvas coordinates */
+
+ FooScrollAreaEventFunc func;
+ gpointer data;
+
+ InputPath *next;
+};
+
+/* InputRegions are mutually disjoint */
+struct InputRegion
+{
+ GdkRegion *region; /* the boundary of this area in canvas coordinates */
+ InputPath *paths;
+};
+
+struct AutoScrollInfo
+{
+ int dx;
+ int dy;
+ int timeout_id;
+ int begin_x;
+ int begin_y;
+ double res_x;
+ double res_y;
+ GTimer *timer;
+};
+
+struct FooScrollAreaPrivate
+{
+ GdkWindow *input_window;
+
+ int width;
+ int height;
+
+ GtkAdjustment *hadj;
+ GtkAdjustment *vadj;
+ int x_offset;
+ int y_offset;
+
+ int min_width;
+ int min_height;
+
+ GPtrArray *input_regions;
+
+ AutoScrollInfo *auto_scroll_info;
+
+ /* During expose, this region is set to the region
+ * being exposed. At other times, it is NULL
+ *
+ * It is used for clipping of input areas
+ */
+ GdkRegion *expose_region;
+ InputRegion *current_input;
+
+ gboolean grabbed;
+ FooScrollAreaEventFunc grab_func;
+ gpointer grab_data;
+
+ GdkPixmap *pixmap;
+ GdkRegion *update_region; /* In canvas coordinates */
+};
+
+enum
+{
+ VIEWPORT_CHANGED,
+ PAINT,
+ INPUT,
+ LAST_SIGNAL,
+};
+
+static guint signals [LAST_SIGNAL] = { 0 };
+
+static void foo_scroll_area_size_request (GtkWidget *widget,
+ GtkRequisition *requisition);
+static gboolean foo_scroll_area_expose (GtkWidget *widget,
+ GdkEventExpose *expose);
+static void foo_scroll_area_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
+static void foo_scroll_area_set_scroll_adjustments (FooScrollArea *scroll_area,
+ GtkAdjustment *hadjustment,
+ GtkAdjustment *vadjustment);
+static void foo_scroll_area_realize (GtkWidget *widget);
+static void foo_scroll_area_unrealize (GtkWidget *widget);
+static void foo_scroll_area_map (GtkWidget *widget);
+static void foo_scroll_area_unmap (GtkWidget *widget);
+static gboolean foo_scroll_area_button_press (GtkWidget *widget,
+ GdkEventButton *event);
+static gboolean foo_scroll_area_button_release (GtkWidget *widget,
+ GdkEventButton *event);
+static gboolean foo_scroll_area_motion (GtkWidget *widget,
+ GdkEventMotion *event);
+
+static void
+foo_scroll_area_map (GtkWidget *widget)
+{
+ FooScrollArea *area = FOO_SCROLL_AREA (widget);
+
+ GTK_WIDGET_CLASS (parent_class)->map (widget);
+
+ if (area->priv->input_window)
+ gdk_window_show (area->priv->input_window);
+}
+
+static void
+foo_scroll_area_unmap (GtkWidget *widget)
+{
+ FooScrollArea *area = FOO_SCROLL_AREA (widget);
+
+ if (area->priv->input_window)
+ gdk_window_hide (area->priv->input_window);
+
+ GTK_WIDGET_CLASS (parent_class)->unmap (widget);
+}
+
+static void
+foo_scroll_area_finalize (GObject *object)
+{
+ FooScrollArea *scroll_area = FOO_SCROLL_AREA (object);
+
+ g_object_unref (scroll_area->priv->hadj);
+ g_object_unref (scroll_area->priv->vadj);
+
+ g_ptr_array_free (scroll_area->priv->input_regions, TRUE);
+
+ g_free (scroll_area->priv);
+
+ G_OBJECT_CLASS (foo_scroll_area_parent_class)->finalize (object);
+}
+
+static void
+foo_scroll_area_class_init (FooScrollAreaClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+
+ object_class->finalize = foo_scroll_area_finalize;
+ widget_class->size_request = foo_scroll_area_size_request;
+ widget_class->expose_event = foo_scroll_area_expose;
+ widget_class->size_allocate = foo_scroll_area_size_allocate;
+ widget_class->realize = foo_scroll_area_realize;
+ widget_class->unrealize = foo_scroll_area_unrealize;
+ widget_class->button_press_event = foo_scroll_area_button_press;
+ widget_class->button_release_event = foo_scroll_area_button_release;
+ widget_class->motion_notify_event = foo_scroll_area_motion;
+ widget_class->map = foo_scroll_area_map;
+ widget_class->unmap = foo_scroll_area_unmap;
+
+ class->set_scroll_adjustments = foo_scroll_area_set_scroll_adjustments;
+
+ parent_class = g_type_class_peek_parent (class);
+
+ signals[VIEWPORT_CHANGED] =
+ g_signal_new ("viewport_changed",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (FooScrollAreaClass,
+ viewport_changed),
+ NULL, NULL,
+ foo_marshal_VOID__BOXED_BOXED,
+ G_TYPE_NONE, 2,
+ GDK_TYPE_RECTANGLE,
+ GDK_TYPE_RECTANGLE);
+
+ signals[PAINT] =
+ g_signal_new ("paint",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (FooScrollAreaClass,
+ paint),
+ NULL, NULL,
+ foo_marshal_VOID__POINTER_BOXED_POINTER,
+ G_TYPE_NONE, 3,
+ G_TYPE_POINTER,
+ GDK_TYPE_RECTANGLE,
+ G_TYPE_POINTER);
+
+ widget_class->set_scroll_adjustments_signal =
+ g_signal_new ("set_scroll_adjustments",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (FooScrollAreaClass,
+ set_scroll_adjustments),
+ NULL, NULL,
+ foo_marshal_VOID__OBJECT_OBJECT,
+ G_TYPE_NONE, 2,
+ GTK_TYPE_ADJUSTMENT,
+ GTK_TYPE_ADJUSTMENT);
+}
+
+static GtkAdjustment *
+new_adjustment (void)
+{
+ return GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
+}
+
+static void
+foo_scroll_area_init (FooScrollArea *scroll_area)
+{
+ GtkWidget *widget;
+
+ widget = GTK_WIDGET (scroll_area);
+
+ gtk_widget_set_has_window (widget, FALSE);
+ gtk_widget_set_redraw_on_allocate (widget, FALSE);
+
+ scroll_area->priv = g_new0 (FooScrollAreaPrivate, 1);
+ scroll_area->priv->width = 0;
+ scroll_area->priv->height = 0;
+ scroll_area->priv->hadj = g_object_ref_sink (new_adjustment());
+ scroll_area->priv->vadj = g_object_ref_sink (new_adjustment());
+ scroll_area->priv->x_offset = 0.0;
+ scroll_area->priv->y_offset = 0.0;
+ scroll_area->priv->min_width = -1;
+ scroll_area->priv->min_height = -1;
+ scroll_area->priv->auto_scroll_info = NULL;
+ scroll_area->priv->input_regions = g_ptr_array_new ();
+ scroll_area->priv->pixmap = NULL;
+ scroll_area->priv->update_region = gdk_region_new ();
+
+ gtk_widget_set_double_buffered (widget, FALSE);
+}
+
+static void
+translate_cairo_device (cairo_t *cr,
+ int x_offset,
+ int y_offset)
+{
+ cairo_surface_t *surface = cairo_get_target (cr);
+ double dev_x;
+ double dev_y;
+
+ cairo_surface_get_device_offset (surface, &dev_x, &dev_y);
+ dev_x += x_offset;
+ dev_y += y_offset;
+ cairo_surface_set_device_offset (surface, dev_x, dev_y);
+}
+
+#if 0
+static void
+print_region (const char *header, GdkRegion *region)
+{
+ GdkRectangle *rects;
+ int n_rects;
+ int i;
+
+ g_print ("%s\n", header);
+
+ gdk_region_get_rectangles (region, &rects, &n_rects);
+ for (i = 0; i < n_rects; ++i)
+ {
+ GdkRectangle *rect = &(rects[i]);
+ g_print (" %d %d %d %d\n",
+ rect->x, rect->y, rect->width, rect->height);
+ }
+}
+#endif
+
+typedef void (* PathForeachFunc) (double *x,
+ double *y,
+ gpointer data);
+
+static void
+path_foreach_point (cairo_path_t *path,
+ PathForeachFunc func,
+ gpointer user_data)
+{
+ int i;
+
+ for (i = 0; i < path->num_data; i += path->data[i].header.length)
+ {
+ cairo_path_data_t *data = &(path->data[i]);
+
+ switch (data->header.type)
+ {
+ case CAIRO_PATH_MOVE_TO:
+ case CAIRO_PATH_LINE_TO:
+ func (&(data[1].point.x), &(data[1].point.y), user_data);
+ break;
+
+ case CAIRO_PATH_CURVE_TO:
+ func (&(data[1].point.x), &(data[1].point.y), user_data);
+ func (&(data[2].point.x), &(data[2].point.y), user_data);
+ func (&(data[3].point.x), &(data[3].point.y), user_data);
+ break;
+
+ case CAIRO_PATH_CLOSE_PATH:
+ break;
+ }
+ }
+}
+
+typedef struct
+{
+ double x1, y1, x2, y2;
+} Box;
+
+#if 0
+static void
+update_box (double *x, double *y, gpointer data)
+{
+ Box *box = data;
+
+ if (*x < box->x1)
+ box->x1 = *x;
+
+ if (*y < box->y1)
+ box->y1 = *y;
+
+ if (*y > box->y2)
+ box->y2 = *y;
+
+ if (*x > box->x2)
+ box->x2 = *x;
+}
+#endif
+
+#if 0
+static void
+path_compute_extents (cairo_path_t *path,
+ GdkRectangle *rect)
+{
+ if (rect)
+ {
+ Box box = { G_MAXDOUBLE, G_MAXDOUBLE, G_MINDOUBLE, G_MINDOUBLE };
+
+ path_foreach_point (path, update_box, &box);
+
+ rect->x = box.x1;
+ rect->y = box.y1;
+ rect->width = box.x2 - box.x1;
+ rect->height = box.y2 - box.y1;
+ }
+}
+#endif
+
+static void
+input_path_free_list (InputPath *paths)
+{
+ if (!paths)
+ return;
+
+ input_path_free_list (paths->next);
+ cairo_path_destroy (paths->path);
+ g_free (paths);
+}
+
+static void
+input_region_free (InputRegion *region)
+{
+ input_path_free_list (region->paths);
+ gdk_region_destroy (region->region);
+
+ g_free (region);
+}
+
+static void
+get_viewport (FooScrollArea *scroll_area,
+ GdkRectangle *viewport)
+{
+ GtkAllocation allocation;
+ GtkWidget *widget = GTK_WIDGET (scroll_area);
+
+ gtk_widget_get_allocation (widget, &allocation);
+
+ viewport->x = scroll_area->priv->x_offset;
+ viewport->y = scroll_area->priv->y_offset;
+ viewport->width = allocation.width;
+ viewport->height = allocation.height;
+}
+
+static void
+allocation_to_canvas (FooScrollArea *area,
+ int *x,
+ int *y)
+{
+ *x += area->priv->x_offset;
+ *y += area->priv->y_offset;
+}
+
+static void
+clear_exposed_input_region (FooScrollArea *area,
+ GdkRegion *exposed) /* in canvas coordinates */
+{
+ int i;
+ GdkRegion *viewport;
+ GdkRectangle allocation;
+
+ gtk_widget_get_allocation (GTK_WIDGET (area), &allocation);
+ allocation.x = 0;
+ allocation.y = 0;
+ allocation_to_canvas (area, &allocation.x, &allocation.y);
+ viewport = gdk_region_rectangle (&allocation);
+ gdk_region_subtract (viewport, exposed);
+
+ for (i = 0; i < area->priv->input_regions->len; ++i)
+ {
+ InputRegion *region = area->priv->input_regions->pdata[i];
+
+ gdk_region_intersect (region->region, viewport);
+
+ if (gdk_region_empty (region->region))
+ {
+ input_region_free (region);
+ g_ptr_array_remove_index_fast (area->priv->input_regions, i--);
+ }
+ }
+
+ gdk_region_destroy (viewport);
+
+#if 0
+ path = region->paths;
+ while (path != NULL)
+ {
+ GdkRectangle rect;
+
+ path_compute_extents (path->path, &rect);
+
+ if (gdk_region_rect_in (area->priv->expose_region, &rect) == GDK_OVERLAP_RECTANGLE_IN)
+ g_print ("we would have deleted it\n");
+#if 0
+ else
+ g_print ("nope (%d %d %d %d)\n", );
+#endif
+
+ path = path->next;
+ }
+
+ /* FIXME: we should also delete paths (and path segments)
+ * completely contained in the expose_region
+ */
+ }
+#endif
+}
+
+static void
+setup_background_cr (GdkWindow *window,
+ cairo_t *cr,
+ int x_offset,
+ int y_offset)
+{
+ GdkWindowObject *private = (GdkWindowObject *)window;
+
+ if (private->bg_pixmap == GDK_PARENT_RELATIVE_BG && private->parent)
+ {
+ x_offset += private->x;
+ y_offset += private->y;
+
+ setup_background_cr (GDK_WINDOW (private->parent), cr, x_offset, y_offset);
+ }
+ else if (private->bg_pixmap &&
+ private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
+ private->bg_pixmap != GDK_NO_BG)
+ {
+ gdk_cairo_set_source_pixmap (cr, private->bg_pixmap, -x_offset, -y_offset);
+ }
+ else
+ {
+ gdk_cairo_set_source_color (cr, &private->bg_color);
+ }
+}
+
+static void
+initialize_background (GtkWidget *widget,
+ cairo_t *cr)
+{
+ setup_background_cr (gtk_widget_get_window (widget), cr, 0, 0);
+
+ cairo_paint (cr);
+}
+
+static void
+clip_to_region (cairo_t *cr, GdkRegion *region)
+{
+ int n_rects;
+ GdkRectangle *rects;
+
+ gdk_region_get_rectangles (region, &rects, &n_rects);
+
+ cairo_new_path (cr);
+ while (n_rects--)
+ {
+ GdkRectangle *rect = &(rects[n_rects]);
+
+ cairo_rectangle (cr, rect->x, rect->y, rect->width, rect->height);
+ }
+ cairo_clip (cr);
+
+ g_free (rects);
+}
+
+static void
+simple_draw_drawable (GdkDrawable *dst,
+ GdkDrawable *src,
+ int src_x,
+ int src_y,
+ int dst_x,
+ int dst_y,
+ int width,
+ int height)
+{
+ GdkGC *gc = gdk_gc_new (dst);
+
+ gdk_draw_drawable (dst, gc, src, src_x, src_y, dst_x, dst_y, width, height);
+
+ g_object_unref (gc);
+}
+
+static gboolean
+foo_scroll_area_expose (GtkWidget *widget,
+ GdkEventExpose *expose)
+{
+ FooScrollArea *scroll_area = FOO_SCROLL_AREA (widget);
+ cairo_t *cr;
+ GdkRectangle extents;
+ GdkRegion *region;
+ int x_offset, y_offset;
+ GdkGC *gc;
+ GtkAllocation widget_allocation;
+ GdkWindow *window = gtk_widget_get_window (widget);
+
+ /* I don't think expose can ever recurse for the same area */
+ g_assert (!scroll_area->priv->expose_region);
+
+ /* Note that this function can be called at a time
+ * where the adj->value is different from x_offset.
+ * Ie., the GtkScrolledWindow changed the adj->value
+ * without emitting the value_changed signal.
+ *
+ * Hence we must always use the value we got
+ * the last time the signal was emitted, ie.,
+ * priv->{x,y}_offset.
+ */
+
+ x_offset = scroll_area->priv->x_offset;
+ y_offset = scroll_area->priv->y_offset;
+
+ scroll_area->priv->expose_region = expose->region;
+
+ /* Setup input areas */
+ clear_exposed_input_region (scroll_area, scroll_area->priv->update_region);
+
+ scroll_area->priv->current_input = g_new0 (InputRegion, 1);
+ scroll_area->priv->current_input->region = gdk_region_copy (scroll_area->priv->update_region);
+ scroll_area->priv->current_input->paths = NULL;
+ g_ptr_array_add (scroll_area->priv->input_regions,
+ scroll_area->priv->current_input);
+
+ region = scroll_area->priv->update_region;
+ scroll_area->priv->update_region = gdk_region_new ();
+
+ /* Create cairo context */
+ cr = gdk_cairo_create (scroll_area->priv->pixmap);
+ translate_cairo_device (cr, -x_offset, -y_offset);
+ clip_to_region (cr, region);
+ initialize_background (widget, cr);
+
+ /* Create regions */
+ gdk_region_get_clipbox (region, &extents);
+
+ g_signal_emit (widget, signals[PAINT], 0, cr, &extents, region);
+
+ /* Destroy stuff */
+ cairo_destroy (cr);
+
+ scroll_area->priv->expose_region = NULL;
+ scroll_area->priv->current_input = NULL;
+
+ /* Finally draw the backing pixmap */
+ gc = gdk_gc_new (window);
+
+ gdk_gc_set_clip_region (gc, expose->region);
+
+ gtk_widget_get_allocation (widget, &widget_allocation);
+ gdk_draw_drawable (window, gc, scroll_area->priv->pixmap,
+ 0, 0, widget_allocation.x, widget_allocation.y,
+ widget_allocation.width, widget_allocation.height);
+
+ g_object_unref (gc);
+ gdk_region_destroy (region);
+
+ return TRUE;
+}
+
+void
+foo_scroll_area_get_viewport (FooScrollArea *scroll_area,
+ GdkRectangle *viewport)
+{
+ g_return_if_fail (FOO_IS_SCROLL_AREA (scroll_area));
+
+ if (!viewport)
+ return;
+
+ get_viewport (scroll_area, viewport);
+}
+
+static void
+process_event (FooScrollArea *scroll_area,
+ FooScrollAreaEventType input_type,
+ int x,
+ int y);
+
+static void
+emit_viewport_changed (FooScrollArea *scroll_area,
+ GdkRectangle *new_viewport,
+ GdkRectangle *old_viewport)
+{
+ int px, py;
+ g_signal_emit (scroll_area, signals[VIEWPORT_CHANGED], 0,
+ new_viewport, old_viewport);
+
+ gdk_window_get_pointer (scroll_area->priv->input_window, &px, &py, NULL);
+
+#if 0
+ g_print ("procc\n");
+#endif
+
+ process_event (scroll_area, FOO_MOTION, px, py);
+}
+
+static void
+clamp_adjustment (GtkAdjustment *adj)
+{
+ if (gtk_adjustment_get_upper (adj) >= gtk_adjustment_get_page_size (adj))
+ gtk_adjustment_set_value (adj, CLAMP (gtk_adjustment_get_value (adj), 0.0,
+ gtk_adjustment_get_upper (adj)
+ - gtk_adjustment_get_page_size (adj)));
+ else
+ gtk_adjustment_set_value (adj, 0.0);
+
+ gtk_adjustment_changed (adj);
+}
+
+static gboolean
+set_adjustment_values (FooScrollArea *scroll_area)
+{
+ GtkAllocation allocation;
+
+ GtkAdjustment *hadj = scroll_area->priv->hadj;
+ GtkAdjustment *vadj = scroll_area->priv->vadj;
+
+ /* Horizontal */
+ gtk_widget_get_allocation (GTK_WIDGET (scroll_area), &allocation);
+ g_object_freeze_notify (G_OBJECT (hadj));
+ gtk_adjustment_set_page_size (hadj, allocation.width);
+ gtk_adjustment_set_step_increment (hadj, 0.1 * allocation.width);
+ gtk_adjustment_set_page_increment (hadj, 0.9 * allocation.width);
+ gtk_adjustment_set_lower (hadj, 0.0);
+ gtk_adjustment_set_upper (hadj, scroll_area->priv->width);
+ g_object_thaw_notify (G_OBJECT (hadj));
+
+ /* Vertical */
+ g_object_freeze_notify (G_OBJECT (vadj));
+ gtk_adjustment_set_page_size (vadj, allocation.height);
+ gtk_adjustment_set_step_increment (vadj, 0.1 * allocation.height);
+ gtk_adjustment_set_page_increment (vadj, 0.9 * allocation.height);
+ gtk_adjustment_set_lower (vadj, 0.0);
+ gtk_adjustment_set_upper (vadj, scroll_area->priv->height);
+ g_object_thaw_notify (G_OBJECT (vadj));
+
+ clamp_adjustment (hadj);
+ clamp_adjustment (vadj);
+
+ return TRUE;
+}
+
+static void
+foo_scroll_area_realize (GtkWidget *widget)
+{
+ FooScrollArea *area = FOO_SCROLL_AREA (widget);
+ GdkWindowAttr attributes;
+ GtkAllocation widget_allocation;
+ GdkWindow *window;
+ gint attributes_mask;
+
+ gtk_widget_get_allocation (widget, &widget_allocation);
+ gtk_widget_set_realized (widget, TRUE);
+
+ attributes.window_type = GDK_WINDOW_CHILD;
+ attributes.x = widget_allocation.x;
+ attributes.y = widget_allocation.y;
+ attributes.width = widget_allocation.width;
+ attributes.height = widget_allocation.height;
+ attributes.wclass = GDK_INPUT_ONLY;
+ attributes.event_mask = gtk_widget_get_events (widget);
+ attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
+ GDK_BUTTON_RELEASE_MASK |
+ GDK_BUTTON1_MOTION_MASK |
+ GDK_BUTTON2_MOTION_MASK |
+ GDK_BUTTON3_MOTION_MASK |
+ GDK_POINTER_MOTION_MASK |
+ GDK_ENTER_NOTIFY_MASK |
+ GDK_LEAVE_NOTIFY_MASK);
+
+ attributes_mask = GDK_WA_X | GDK_WA_Y;
+
+ window = gtk_widget_get_parent_window (widget);
+ gtk_widget_set_window (widget, window);
+ g_object_ref (window);
+
+ area->priv->input_window = gdk_window_new (window,
+ &attributes, attributes_mask);
+ area->priv->pixmap = gdk_pixmap_new (window,
+ widget_allocation.width,
+ widget_allocation.height,
+ -1);
+ gdk_window_set_user_data (area->priv->input_window, area);
+
+ gtk_widget_style_attach (widget);
+}
+
+static void
+foo_scroll_area_unrealize (GtkWidget *widget)
+{
+ FooScrollArea *area = FOO_SCROLL_AREA (widget);
+
+ if (area->priv->input_window)
+ {
+ gdk_window_set_user_data (area->priv->input_window, NULL);
+ gdk_window_destroy (area->priv->input_window);
+ area->priv->input_window = NULL;
+ }
+
+ GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
+}
+
+static GdkPixmap *
+create_new_pixmap (GtkWidget *widget,
+ GdkPixmap *old)
+{
+ GtkAllocation widget_allocation;
+ GdkPixmap *new;
+
+ gtk_widget_get_allocation (widget, &widget_allocation);
+ new = gdk_pixmap_new (gtk_widget_get_window (widget),
+ widget_allocation.width,
+ widget_allocation.height,
+ -1);
+
+ /* Unfortunately we don't know in which direction we were resized,
+ * so we just assume we were dragged from the south-east corner.
+ *
+ * Although, maybe we could get the root coordinates of the input-window?
+ * That might just work, actually. We need to make sure marco uses
+ * static gravity for the window before this will be useful.
+ */
+ simple_draw_drawable (new, old, 0, 0, 0, 0, -1, -1);
+
+ return new;
+}
+
+static void
+allocation_to_canvas_region (FooScrollArea *area,
+ GdkRegion *region)
+{
+ gdk_region_offset (region, area->priv->x_offset, area->priv->y_offset);
+}
+
+
+static void
+foo_scroll_area_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ FooScrollArea *scroll_area = FOO_SCROLL_AREA (widget);
+ GdkRectangle new_viewport;
+ GdkRectangle old_viewport;
+ GdkRegion *old_allocation;
+ GdkRegion *invalid;
+ GtkAllocation widget_allocation;
+
+ get_viewport (scroll_area, &old_viewport);
+
+ gtk_widget_get_allocation (widget, &widget_allocation);
+ old_allocation = gdk_region_rectangle (&widget_allocation);
+ gdk_region_offset (old_allocation,
+ -widget_allocation.x, -widget_allocation.y);
+ invalid = gdk_region_rectangle (allocation);
+ gdk_region_offset (invalid, -allocation->x, -allocation->y);
+ gdk_region_xor (invalid, old_allocation);
+ allocation_to_canvas_region (scroll_area, invalid);
+ foo_scroll_area_invalidate_region (scroll_area, invalid);
+ gdk_region_destroy (old_allocation);
+ gdk_region_destroy (invalid);
+
+ gtk_widget_set_allocation (widget, allocation);
+
+ if (scroll_area->priv->input_window)
+ {
+ GdkPixmap *new_pixmap;
+
+ gdk_window_move_resize (scroll_area->priv->input_window,
+ allocation->x, allocation->y,
+ allocation->width, allocation->height);
+
+ new_pixmap = create_new_pixmap (widget, scroll_area->priv->pixmap);
+
+ g_object_unref (scroll_area->priv->pixmap);
+
+ scroll_area->priv->pixmap = new_pixmap;
+ }
+
+ get_viewport (scroll_area, &new_viewport);
+
+ emit_viewport_changed (scroll_area, &new_viewport, &old_viewport);
+}
+
+static void
+emit_input (FooScrollArea *scroll_area,
+ FooScrollAreaEventType type,
+ int x,
+ int y,
+ FooScrollAreaEventFunc func,
+ gpointer data)
+{
+ FooScrollAreaEvent event;
+
+ if (!func)
+ return;
+
+ if (type != FOO_MOTION)
+ emit_input (scroll_area, FOO_MOTION, x, y, func, data);
+
+#if 0
+ x += scroll_area->priv->x_offset;
+ y += scroll_area->priv->y_offset;
+#endif
+
+ event.type = type;
+ event.x = x;
+ event.y = y;
+
+ func (scroll_area, &event, data);
+}
+
+#if 0
+static void
+print_path (const char *header,
+ cairo_path_t *path)
+{
+ int i;
+
+ g_print ("%s\n", header);
+
+ for (i=0; i < path->num_data; i += path->data[i].header.length)
+ {
+ cairo_path_data_t *data = &(path->data[i]);
+
+ switch (data->header.type)
+ {
+ case CAIRO_PATH_MOVE_TO:
+ g_print ("move to: %f, %f\n", data[1].point.x, data[1].point.y);
+ break;
+
+ case CAIRO_PATH_LINE_TO:
+ g_print ("line to: %f, %f\n", data[1].point.x, data[1].point.y);
+ break;
+
+ case CAIRO_PATH_CURVE_TO:
+ g_print ("curve to: %f, %f\n", data[1].point.x, data[1].point.y);
+ g_print (" %f, %f\n", data[1].point.x, data[1].point.y);
+ g_print (" %f, %f\n", data[1].point.x, data[1].point.y);
+ break;
+
+ case CAIRO_PATH_CLOSE_PATH:
+ break;
+ }
+ }
+}
+#endif
+
+static void
+process_event (FooScrollArea *scroll_area,
+ FooScrollAreaEventType input_type,
+ int x,
+ int y)
+{
+ GtkWidget *widget = GTK_WIDGET (scroll_area);
+ int i;
+
+ allocation_to_canvas (scroll_area, &x, &y);
+
+ if (scroll_area->priv->grabbed)
+ {
+ emit_input (scroll_area, input_type, x, y,
+ scroll_area->priv->grab_func,
+ scroll_area->priv->grab_data);
+ return;
+ }
+
+
+#if 0
+ x += widget->allocation.x;
+ y += widget->allocation.y;
+#endif
+
+#if 0
+ g_print ("number of input regions: %d\n", scroll_area->priv->input_regions->len);
+#endif
+
+ for (i = 0; i < scroll_area->priv->input_regions->len; ++i)
+ {
+ InputRegion *region = scroll_area->priv->input_regions->pdata[i];
+
+#if 0
+ g_print ("%d ", i);
+ print_region ("region:", region->region);
+#endif
+
+ if (gdk_region_point_in (region->region, x, y))
+ {
+ InputPath *path;
+
+ path = region->paths;
+ while (path)
+ {
+ cairo_t *cr;
+ gboolean inside;
+
+ cr = gdk_cairo_create (gtk_widget_get_window (widget));
+ cairo_set_fill_rule (cr, path->fill_rule);
+ cairo_set_line_width (cr, path->line_width);
+ cairo_append_path (cr, path->path);
+
+ if (path->is_stroke)
+ inside = cairo_in_stroke (cr, x, y);
+ else
+ inside = cairo_in_fill (cr, x, y);
+
+ cairo_destroy (cr);
+
+ if (inside)
+ {
+ emit_input (scroll_area, input_type,
+ x, y,
+ path->func,
+ path->data);
+ return;
+ }
+
+ path = path->next;
+ }
+
+ /* Since the regions are all disjoint, no other region
+ * can match. Of course we could be clever and try and
+ * sort the regions, but so far I have been unable to
+ * make this loop show up on a profile.
+ */
+ return;
+ }
+ }
+}
+
+static void
+process_gdk_event (FooScrollArea *scroll_area,
+ int x,
+ int y,
+ GdkEvent *event)
+{
+ FooScrollAreaEventType input_type;
+
+ if (event->type == GDK_BUTTON_PRESS)
+ input_type = FOO_BUTTON_PRESS;
+ else if (event->type == GDK_BUTTON_RELEASE)
+ input_type = FOO_BUTTON_RELEASE;
+ else if (event->type == GDK_MOTION_NOTIFY)
+ input_type = FOO_MOTION;
+ else
+ return;
+
+ process_event (scroll_area, input_type, x, y);
+}
+
+static gboolean
+foo_scroll_area_button_press (GtkWidget *widget,
+ GdkEventButton *event)
+{
+ FooScrollArea *area = FOO_SCROLL_AREA (widget);
+
+ process_gdk_event (area, event->x, event->y, (GdkEvent *)event);
+
+ return TRUE;
+}
+
+static gboolean
+foo_scroll_area_button_release (GtkWidget *widget,
+ GdkEventButton *event)
+{
+ FooScrollArea *area = FOO_SCROLL_AREA (widget);
+
+ process_gdk_event (area, event->x, event->y, (GdkEvent *)event);
+
+ return FALSE;
+}
+
+static gboolean
+foo_scroll_area_motion (GtkWidget *widget,
+ GdkEventMotion *event)
+{
+ FooScrollArea *area = FOO_SCROLL_AREA (widget);
+
+ process_gdk_event (area, event->x, event->y, (GdkEvent *)event);
+ return TRUE;
+}
+
+void
+foo_scroll_area_set_size_fixed_y (FooScrollArea *scroll_area,
+ int width,
+ int height,
+ int old_y,
+ int new_y)
+{
+ scroll_area->priv->width = width;
+ scroll_area->priv->height = height;
+
+#if 0
+ g_print ("diff: %d\n", new_y - old_y);
+#endif
+ g_object_thaw_notify (G_OBJECT (scroll_area->priv->vadj));
+ gtk_adjustment_set_value (scroll_area->priv->vadj, new_y);
+
+ set_adjustment_values (scroll_area);
+ g_object_thaw_notify (G_OBJECT (scroll_area->priv->vadj));
+}
+
+void
+foo_scroll_area_set_size (FooScrollArea *scroll_area,
+ int width,
+ int height)
+{
+ g_return_if_fail (FOO_IS_SCROLL_AREA (scroll_area));
+
+ /* FIXME: Default scroll algorithm should probably be to
+ * keep the same *area* outside the screen as before.
+ *
+ * For wrapper widgets that will do something roughly
+ * right. For widgets that don't change size, it
+ * will do the right thing. Except for idle-layouting
+ * widgets.
+ *
+ * Maybe there should be some generic support for those
+ * widgets. Can that even be done?
+ *
+ * Should we have a version of this function using
+ * fixed points?
+ */
+
+ scroll_area->priv->width = width;
+ scroll_area->priv->height = height;
+
+ set_adjustment_values (scroll_area);
+}
+
+static void
+foo_scroll_area_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
+{
+ FooScrollArea *scroll_area = FOO_SCROLL_AREA (widget);
+
+ requisition->width = scroll_area->priv->min_width;
+ requisition->height = scroll_area->priv->min_height;
+
+#if 0
+ g_print ("request %d %d\n", requisition->width, requisition->height);
+#endif
+}
+
+#if 0
+static void
+translate_point (double *x, double *y, gpointer data)
+{
+ int *translation = data;
+
+ *x += translation[0];
+ *y += translation[1];
+}
+#endif
+
+#if 0
+static void
+path_translate (cairo_path_t *path,
+ int dx,
+ int dy)
+{
+ int translation[2] = {dx, dy};
+
+ path_foreach_point (path, translate_point, translation);
+}
+#endif
+
+static void
+translate_input_regions (FooScrollArea *scroll_area,
+ int dx,
+ int dy)
+{
+#if 0
+ int i;
+
+ for (i = 0; i < scroll_area->priv->input_regions->len; ++i)
+ {
+ InputRegion *region = scroll_area->priv->input_regions->pdata[i];
+ InputPath *path;
+
+ gdk_region_offset (region->region, dx, dy);
+
+ path = region->paths;
+ while (path != NULL)
+ {
+ path_translate (path->path, dx, dy);
+ path = path->next;
+ }
+ }
+#endif
+}
+
+#if 0
+static void
+paint_region (FooScrollArea *area, GdkRegion *region)
+{
+ int n_rects;
+ GdkRectangle *rects;
+ region = gdk_region_copy (region);
+
+ gdk_region_get_rectangles (region, &rects, &n_rects);
+
+ gdk_region_offset (region,
+ GTK_WIDGET (area)->allocation.x,
+ GTK_WIDGET (area)->allocation.y);
+
+ GdkGC *gc = gdk_gc_new (GTK_WIDGET (area)->window);
+ gdk_gc_set_clip_region (gc, region);
+ gdk_draw_rectangle (GTK_WIDGET (area)->window, gc, TRUE, 0, 0, -1, -1);
+ g_object_unref (gc);
+ g_free (rects);
+}
+#endif
+
+static void
+foo_scroll_area_scroll (FooScrollArea *area,
+ gint dx,
+ gint dy)
+{
+ GdkRectangle allocation;
+ GdkRectangle src_area;
+ GdkRectangle move_area;
+ GdkRegion *invalid_region;
+
+ gtk_widget_get_allocation (GTK_WIDGET (area), &allocation);
+ allocation.x = 0;
+ allocation.y = 0;
+
+ src_area = allocation;
+ src_area.x -= dx;
+ src_area.y -= dy;
+
+ invalid_region = gdk_region_rectangle (&allocation);
+
+ if (gdk_rectangle_intersect (&allocation, &src_area, &move_area))
+ {
+ GdkRegion *move_region;
+
+#if 0
+ g_print ("scrolling %d %d %d %d (%d %d)\n",
+ move_area.x, move_area.y,
+ move_area.width, move_area.height,
+ dx, dy);
+#endif
+
+ simple_draw_drawable (area->priv->pixmap, area->priv->pixmap,
+ move_area.x, move_area.y,
+ move_area.x + dx, move_area.y + dy,
+ move_area.width, move_area.height);
+ gtk_widget_queue_draw (GTK_WIDGET (area));
+
+ move_region = gdk_region_rectangle (&move_area);
+ gdk_region_offset (move_region, dx, dy);
+ gdk_region_subtract (invalid_region, move_region);
+ gdk_region_destroy (move_region);
+ }
+
+#if 0
+ paint_region (area, invalid_region);
+#endif
+
+ allocation_to_canvas_region (area, invalid_region);
+
+ foo_scroll_area_invalidate_region (area, invalid_region);
+
+ gdk_region_destroy (invalid_region);
+}
+
+static void
+foo_scrollbar_adjustment_changed (GtkAdjustment *adj,
+ FooScrollArea *scroll_area)
+{
+ GtkWidget *widget = GTK_WIDGET (scroll_area);
+ gint dx = 0;
+ gint dy = 0;
+ GdkRectangle old_viewport, new_viewport;
+
+ get_viewport (scroll_area, &old_viewport);
+
+ if (adj == scroll_area->priv->hadj)
+ {
+ /* FIXME: do we treat the offset as int or double, and,
+ * if int, how do we round?
+ */
+ dx = (int)gtk_adjustment_get_value (adj) - scroll_area->priv->x_offset;
+ scroll_area->priv->x_offset = gtk_adjustment_get_value (adj);
+ }
+ else if (adj == scroll_area->priv->vadj)
+ {
+ dy = (int)gtk_adjustment_get_value (adj) - scroll_area->priv->y_offset;
+ scroll_area->priv->y_offset = gtk_adjustment_get_value (adj);
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+
+ if (gtk_widget_get_realized (widget))
+ {
+ foo_scroll_area_scroll (scroll_area, -dx, -dy);
+
+#if 0
+ window_scroll_area (widget->window, &widget->allocation, -dx, -dy);
+#endif
+ translate_input_regions (scroll_area, -dx, -dy);
+
+#if 0
+ gdk_window_process_updates (widget->window, TRUE);
+#endif
+ }
+
+ get_viewport (scroll_area, &new_viewport);
+
+ emit_viewport_changed (scroll_area, &new_viewport, &old_viewport);
+}
+
+static void
+set_one_adjustment (FooScrollArea *scroll_area,
+ GtkAdjustment *adjustment,
+ GtkAdjustment **location)
+{
+ g_return_if_fail (location != NULL);
+
+ if (adjustment == *location)
+ return;
+
+ if (!adjustment)
+ adjustment = new_adjustment ();
+
+ g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+
+ if (*location)
+ {
+ g_signal_handlers_disconnect_by_func (
+ *location, foo_scrollbar_adjustment_changed, scroll_area);
+
+ g_object_unref (*location);
+ }
+
+ *location = adjustment;
+
+ g_object_ref_sink (*location);
+
+ g_signal_connect (*location, "value_changed",
+ G_CALLBACK (foo_scrollbar_adjustment_changed),
+ scroll_area);
+}
+
+static void
+foo_scroll_area_set_scroll_adjustments (FooScrollArea *scroll_area,
+ GtkAdjustment *hadjustment,
+ GtkAdjustment *vadjustment)
+{
+ set_one_adjustment (scroll_area, hadjustment, &scroll_area->priv->hadj);
+ set_one_adjustment (scroll_area, vadjustment, &scroll_area->priv->vadj);
+
+ set_adjustment_values (scroll_area);
+}
+
+FooScrollArea *
+foo_scroll_area_new (void)
+{
+ return g_object_new (FOO_TYPE_SCROLL_AREA, NULL);
+}
+
+void
+foo_scroll_area_set_min_size (FooScrollArea *scroll_area,
+ int min_width,
+ int min_height)
+{
+ scroll_area->priv->min_width = min_width;
+ scroll_area->priv->min_height = min_height;
+
+ /* FIXME: think through invalidation.
+ *
+ * Goals: - no repainting everything on size_allocate(),
+ * - make sure input boxes are invalidated when
+ * needed
+ */
+ gtk_widget_queue_resize (GTK_WIDGET (scroll_area));
+}
+
+#if 0
+static void
+warn_about_adding_input_outside_expose (const char *func)
+{
+ static gboolean warned = FALSE;
+
+ if (!warned)
+ {
+ g_warning ("%s() can only be called "
+ "from the paint handler for the FooScrollArea\n", func);
+
+ warned = TRUE;
+ }
+}
+#endif
+
+static void
+user_to_device (double *x, double *y,
+ gpointer data)
+{
+ cairo_t *cr = data;
+
+ cairo_user_to_device (cr, x, y);
+}
+
+static InputPath *
+make_path (FooScrollArea *area,
+ cairo_t *cr,
+ gboolean is_stroke,
+ FooScrollAreaEventFunc func,
+ gpointer data)
+{
+ InputPath *path = g_new0 (InputPath, 1);
+
+ path->is_stroke = is_stroke;
+ path->fill_rule = cairo_get_fill_rule (cr);
+ path->line_width = cairo_get_line_width (cr);
+ path->path = cairo_copy_path (cr);
+ path_foreach_point (path->path, user_to_device, cr);
+ path->func = func;
+ path->data = data;
+ path->next = area->priv->current_input->paths;
+ area->priv->current_input->paths = path;
+ return path;
+}
+
+/* FIXME: we probably really want a
+ *
+ * foo_scroll_area_add_input_from_fill (area, cr, ...);
+ * and
+ * foo_scroll_area_add_input_from_stroke (area, cr, ...);
+ * as well.
+ */
+void
+foo_scroll_area_add_input_from_fill (FooScrollArea *scroll_area,
+ cairo_t *cr,
+ FooScrollAreaEventFunc func,
+ gpointer data)
+{
+ g_return_if_fail (FOO_IS_SCROLL_AREA (scroll_area));
+ g_return_if_fail (cr != NULL);
+ g_return_if_fail (scroll_area->priv->current_input);
+
+ make_path (scroll_area, cr, FALSE, func, data);
+}
+
+void
+foo_scroll_area_add_input_from_stroke (FooScrollArea *scroll_area,
+ cairo_t *cr,
+ FooScrollAreaEventFunc func,
+ gpointer data)
+{
+ g_return_if_fail (FOO_IS_SCROLL_AREA (scroll_area));
+ g_return_if_fail (cr != NULL);
+ g_return_if_fail (scroll_area->priv->current_input);
+
+ make_path (scroll_area, cr, TRUE, func, data);
+}
+
+void
+foo_scroll_area_invalidate (FooScrollArea *scroll_area)
+{
+ GtkAllocation allocation;
+ GtkWidget *widget = GTK_WIDGET (scroll_area);
+
+ gtk_widget_get_allocation (widget, &allocation);
+ foo_scroll_area_invalidate_rect (scroll_area,
+ scroll_area->priv->x_offset, scroll_area->priv->y_offset,
+ allocation.width,
+ allocation.height);
+}
+
+static void
+canvas_to_window (FooScrollArea *area,
+ GdkRegion *region)
+{
+ GtkAllocation allocation;
+ GtkWidget *widget = GTK_WIDGET (area);
+
+ gtk_widget_get_allocation (widget, &allocation);
+ gdk_region_offset (region,
+ -area->priv->x_offset + allocation.x,
+ -area->priv->y_offset + allocation.y);
+}
+
+static void
+window_to_canvas (FooScrollArea *area,
+ GdkRegion *region)
+{
+ GtkAllocation allocation;
+ GtkWidget *widget = GTK_WIDGET (area);
+
+ gtk_widget_get_allocation (widget, &allocation);
+ gdk_region_offset (region,
+ area->priv->x_offset - allocation.x,
+ area->priv->y_offset - allocation.y);
+}
+
+void
+foo_scroll_area_invalidate_region (FooScrollArea *area,
+ GdkRegion *region)
+{
+ GtkWidget *widget;
+
+ g_return_if_fail (FOO_IS_SCROLL_AREA (area));
+
+ widget = GTK_WIDGET (area);
+
+ gdk_region_union (area->priv->update_region, region);
+
+ if (gtk_widget_get_realized (widget))
+ {
+ canvas_to_window (area, region);
+
+ gdk_window_invalidate_region (gtk_widget_get_window (widget),
+ region, TRUE);
+
+ window_to_canvas (area, region);
+ }
+}
+
+void
+foo_scroll_area_invalidate_rect (FooScrollArea *scroll_area,
+ int x,
+ int y,
+ int width,
+ int height)
+{
+ GdkRectangle rect = { x, y, width, height };
+ GdkRegion *region;
+
+ g_return_if_fail (FOO_IS_SCROLL_AREA (scroll_area));
+
+ region = gdk_region_rectangle (&rect);
+
+ foo_scroll_area_invalidate_region (scroll_area, region);
+
+ gdk_region_destroy (region);
+}
+
+void
+foo_scroll_area_begin_grab (FooScrollArea *scroll_area,
+ FooScrollAreaEventFunc func,
+ gpointer input_data)
+{
+ g_return_if_fail (FOO_IS_SCROLL_AREA (scroll_area));
+ g_return_if_fail (!scroll_area->priv->grabbed);
+
+ scroll_area->priv->grabbed = TRUE;
+ scroll_area->priv->grab_func = func;
+ scroll_area->priv->grab_data = input_data;
+
+ /* FIXME: we should probably take a server grab */
+ /* Also, maybe there should be support for setting the grab cursor */
+}
+
+void
+foo_scroll_area_end_grab (FooScrollArea *scroll_area)
+{
+ g_return_if_fail (FOO_IS_SCROLL_AREA (scroll_area));
+
+ scroll_area->priv->grabbed = FALSE;
+ scroll_area->priv->grab_func = NULL;
+ scroll_area->priv->grab_data = NULL;
+}
+
+gboolean
+foo_scroll_area_is_grabbed (FooScrollArea *scroll_area)
+{
+ return scroll_area->priv->grabbed;
+}
+
+void
+foo_scroll_area_set_viewport_pos (FooScrollArea *scroll_area,
+ int x,
+ int y)
+{
+ g_object_freeze_notify (G_OBJECT (scroll_area->priv->hadj));
+ g_object_freeze_notify (G_OBJECT (scroll_area->priv->vadj));
+ gtk_adjustment_set_value (scroll_area->priv->hadj, x);
+ gtk_adjustment_set_value (scroll_area->priv->vadj, y);
+
+ set_adjustment_values (scroll_area);
+ g_object_thaw_notify (G_OBJECT (scroll_area->priv->hadj));
+ g_object_thaw_notify (G_OBJECT (scroll_area->priv->vadj));
+}
+
+static gboolean
+rect_contains (const GdkRectangle *rect, int x, int y)
+{
+ return (x >= rect->x &&
+ y >= rect->y &&
+ x < rect->x + rect->width &&
+ y < rect->y + rect->height);
+}
+
+static void
+stop_scrolling (FooScrollArea *area)
+{
+#if 0
+ g_print ("stop scrolling\n");
+#endif
+ if (area->priv->auto_scroll_info)
+ {
+ g_source_remove (area->priv->auto_scroll_info->timeout_id);
+ g_timer_destroy (area->priv->auto_scroll_info->timer);
+ g_free (area->priv->auto_scroll_info);
+
+ area->priv->auto_scroll_info = NULL;
+ }
+}
+
+static gboolean
+scroll_idle (gpointer data)
+{
+ GdkRectangle viewport, new_viewport;
+ FooScrollArea *area = data;
+ AutoScrollInfo *info = area->priv->auto_scroll_info;
+#if 0
+ int dx, dy;
+#endif
+ int new_x, new_y;
+ double elapsed;
+
+ get_viewport (area, &viewport);
+
+#if 0
+ g_print ("old info: %d %d\n", info->dx, info->dy);
+
+ g_print ("timeout (%d %d)\n", dx, dy);
+#endif
+
+#if 0
+ viewport.x += info->dx;
+ viewport.y += info->dy;
+#endif
+
+#if 0
+ g_print ("new info %d %d\n", info->dx, info->dy);
+#endif
+
+ elapsed = g_timer_elapsed (info->timer, NULL);
+
+ info->res_x = elapsed * info->dx / 0.2;
+ info->res_y = elapsed * info->dy / 0.2;
+
+#if 0
+ g_print ("%f %f\n", info->res_x, info->res_y);
+#endif
+
+ new_x = viewport.x + info->res_x;
+ new_y = viewport.y + info->res_y;
+
+#if 0
+ g_print ("%f\n", elapsed * (info->dx / 0.2));
+#endif
+
+#if 0
+ g_print ("new_x, new_y\n: %d %d\n", new_x, new_y);
+#endif
+
+ foo_scroll_area_set_viewport_pos (area, new_x, new_y);
+#if 0
+ viewport.x + info->dx,
+ viewport.y + info->dy);
+#endif
+
+ get_viewport (area, &new_viewport);
+
+ if (viewport.x == new_viewport.x &&
+ viewport.y == new_viewport.y &&
+ (info->res_x > 1.0 ||
+ info->res_y > 1.0 ||
+ info->res_x < -1.0 ||
+ info->res_y < -1.0))
+ {
+ stop_scrolling (area);
+
+ /* stop scrolling if it didn't have an effect */
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void
+ensure_scrolling (FooScrollArea *area,
+ int dx,
+ int dy)
+{
+ if (!area->priv->auto_scroll_info)
+ {
+#if 0
+ g_print ("start scrolling\n");
+#endif
+ area->priv->auto_scroll_info = g_new0 (AutoScrollInfo, 1);
+ area->priv->auto_scroll_info->timeout_id =
+ g_idle_add (scroll_idle, area);
+ area->priv->auto_scroll_info->timer = g_timer_new ();
+ }
+
+#if 0
+ g_print ("setting scrolling to %d %d\n", dx, dy);
+#endif
+
+#if 0
+ g_print ("dx, dy: %d %d\n", dx, dy);
+#endif
+
+ area->priv->auto_scroll_info->dx = dx;
+ area->priv->auto_scroll_info->dy = dy;
+}
+
+void
+foo_scroll_area_auto_scroll (FooScrollArea *scroll_area,
+ FooScrollAreaEvent *event)
+{
+ GdkRectangle viewport;
+
+ get_viewport (scroll_area, &viewport);
+
+ if (rect_contains (&viewport, event->x, event->y))
+ {
+ stop_scrolling (scroll_area);
+ }
+ else
+ {
+ int dx, dy;
+
+ dx = dy = 0;
+
+ if (event->y < viewport.y)
+ {
+ dy = event->y - viewport.y;
+ dy = MIN (dy + 2, 0);
+ }
+ else if (event->y >= viewport.y + viewport.height)
+ {
+ dy = event->y - (viewport.y + viewport.height - 1);
+ dy = MAX (dy - 2, 0);
+ }
+
+ if (event->x < viewport.x)
+ {
+ dx = event->x - viewport.x;
+ dx = MIN (dx + 2, 0);
+ }
+ else if (event->x >= viewport.x + viewport.width)
+ {
+ dx = event->x - (viewport.x + viewport.width - 1);
+ dx = MAX (dx - 2, 0);
+ }
+
+#if 0
+ g_print ("dx, dy: %d %d\n", dx, dy);
+#endif
+
+ ensure_scrolling (scroll_area, dx, dy);
+ }
+}
+
+void
+foo_scroll_area_begin_auto_scroll (FooScrollArea *scroll_area)
+{
+ /* noop for now */
+}
+
+void
+foo_scroll_area_end_auto_scroll (FooScrollArea *scroll_area)
+{
+ stop_scrolling (scroll_area);
+}
+
+
+
+#if 0
+/*
+ * Backing Store
+ */
+struct BackingStore
+{
+ GdkPixmap *pixmap;
+ GdkRegion *update_region;
+ int width;
+ int height;
+};
+
+static BackingStore *
+backing_store_new (GdkWindow *window,
+ int width, int height)
+{
+ BackingStore *store = g_new0 (BackingStore, 1);
+ GdkRectangle rect = { 0, 0, width, height };
+
+ store->pixmap = gdk_pixmap_new (window, width, height, -1);
+ store->update_region = gdk_region_rectangle (&rect);
+ store->width = width;
+ store->height = height;
+
+ return store;
+}
+
+static void
+backing_store_free (BackingStore *store)
+{
+ g_object_unref (store->pixmap);
+ gdk_region_destroy (store->update_region);
+ g_free (store);
+}
+
+static void
+backing_store_draw (BackingStore *store,
+ GdkDrawable *dest,
+ GdkRegion *clip,
+ int x,
+ int y)
+{
+ GdkGC *gc = gdk_gc_new (dest);
+
+ gdk_gc_set_clip_region (gc, clip);
+
+ gdk_draw_drawable (dest, gc, store->pixmap,
+ 0, 0, x, y, store->width, store->height);
+
+ g_object_unref (gc);
+}
+
+static void
+backing_store_scroll (BackingStore *store,
+ int dx,
+ int dy)
+{
+ GdkGC *gc = gdk_gc_new (store->pixmap);
+ GdkRectangle rect;
+
+ gdk_draw_drawable (store->pixmap, gc, store->pixmap,
+ 0, 0, dx, dy,
+ store->width, store->height);
+
+ /* Invalidate vertically */
+ rect.x = 0;
+ rect.width = store->width;
+
+ if (dy > 0)
+ {
+ rect.y = 0;
+ rect.height = dy;
+ }
+ else
+ {
+ rect.y = store->height + dy;
+ rect.y = -dy;
+ }
+
+ gdk_region_union_with_rect (store->update_region, &rect);
+
+ /* Invalidate horizontally */
+ rect.y = 0;
+ rect.height = store->height;
+
+ if (dx > 0)
+ {
+ rect.x = 0;
+ rect.width = dx;
+ }
+ else
+ {
+ rect.x = store->width + dx;
+ rect.width = -dx;
+ }
+
+ gdk_region_union_with_rect (store->update_region, &rect);
+}
+
+static void
+backing_store_invalidate_rect (BackingStore *store,
+ GdkRectangle *rect)
+{
+ gdk_region_union_with_rect (store->update_region, rect);
+}
+
+static void
+backing_store_invalidate_region (BackingStore *store,
+ GdkRegion *region)
+{
+ gdk_region_union (store->update_region, region);
+}
+
+static void
+backing_store_invalidate_all (BackingStore *store)
+{
+ GdkRectangle rect = { 0, 0, store->width, store->height };
+ gdk_region_destroy (store->update_region);
+ store->update_region = gdk_region_rectangle (&rect);
+}
+
+static void
+backing_store_resize (BackingStore *store,
+ int width,
+ int height)
+{
+ GdkPixmap *pixmap = gdk_pixmap_new (store->pixmap, width, height, -1);
+
+ /* Unfortunately we don't know in which direction we were resized,
+ * so we just assume we were dragged from the south-east corner.
+ *
+ * Although, maybe we could get the root coordinates of the input-window?
+ * That might just work, actually. We need to make sure marco uses
+ * static gravity for the window before this will be useful.
+ */
+ simple_draw_drawable (pixmap, store->pixmap, 0, 0, 0, 0, -1, -1);
+
+ g_object_unref (store->pixmap);
+
+ store->pixmap = pixmap;
+
+ /* FIXME: invalidate uncovered strip only */
+
+ backing_store_invalidate_all (store);
+}
+
+static void
+cclip_to_region (cairo_t *cr, GdkRegion *region)
+{
+ int n_rects;
+ GdkRectangle *rects;
+
+ gdk_region_get_rectangles (region, &rects, &n_rects);
+
+ cairo_new_path (cr);
+ while (n_rects--)
+ {
+ GdkRectangle *rect = &(rects[n_rects]);
+
+ cairo_rectangle (cr, rect->x, rect->y, rect->width, rect->height);
+ }
+ cairo_clip (cr);
+
+ g_free (rects);
+}
+
+static void
+backing_store_process_updates (BackingStore *store,
+ ExposeFunc func,
+ gpointer data)
+{
+ cairo_t *cr = gdk_cairo_create (store->pixmap);
+ GdkRegion *region = store->update_region;
+ store->update_region = gdk_region_new ();
+
+ cclip_to_region (cr, store->update_region);
+
+ func (cr, store->update_region, data);
+
+ gdk_region_destroy (region);
+ cairo_destroy (cr);
+}
+
+#endif
diff --git a/capplets/display/scrollarea.h b/capplets/display/scrollarea.h
new file mode 100644
index 00000000..d1695fad
--- /dev/null
+++ b/capplets/display/scrollarea.h
@@ -0,0 +1,124 @@
+/* Copyright 2006, 2007, 2008, Soren Sandmann <[email protected]>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include <cairo.h>
+#include <gtk/gtk.h>
+
+#define FOO_TYPE_SCROLL_AREA (foo_scroll_area_get_type ())
+#define FOO_SCROLL_AREA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FOO_TYPE_SCROLL_AREA, FooScrollArea))
+#define FOO_SCROLL_AREA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FOO_TYPE_SCROLL_AREA, FooScrollAreaClass))
+#define FOO_IS_SCROLL_AREA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FOO_TYPE_SCROLL_AREA))
+#define FOO_IS_SCROLL_AREA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FOO_TYPE_SCROLL_AREA))
+#define FOO_SCROLL_AREA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FOO_TYPE_SCROLL_AREA, FooScrollAreaClass))
+
+typedef struct FooScrollArea FooScrollArea;
+typedef struct FooScrollAreaClass FooScrollAreaClass;
+typedef struct FooScrollAreaPrivate FooScrollAreaPrivate;
+typedef struct FooScrollAreaEvent FooScrollAreaEvent;
+
+typedef enum
+{
+ FOO_BUTTON_PRESS,
+ FOO_BUTTON_RELEASE,
+ FOO_MOTION
+} FooScrollAreaEventType;
+
+struct FooScrollAreaEvent
+{
+ FooScrollAreaEventType type;
+ int x;
+ int y;
+};
+
+typedef void (* FooScrollAreaEventFunc) (FooScrollArea *area,
+ FooScrollAreaEvent *event,
+ gpointer data);
+
+struct FooScrollArea
+{
+ GtkContainer parent_instance;
+
+ FooScrollAreaPrivate *priv;
+};
+
+struct FooScrollAreaClass
+{
+ GtkContainerClass parent_class;
+
+ void (*set_scroll_adjustments) (FooScrollArea *scroll_area,
+ GtkAdjustment *hadjustment,
+ GtkAdjustment *vadjustment);
+
+ void (*viewport_changed) (FooScrollArea *scroll_area,
+ GdkRectangle *old_viewport,
+ GdkRectangle *new_viewport);
+
+ void (*paint) (FooScrollArea *scroll_area,
+ cairo_t *cr,
+ GdkRectangle *extents,
+ GdkRegion *region);
+};
+
+GType foo_scroll_area_get_type (void);
+
+FooScrollArea *foo_scroll_area_new (void);
+
+/* Set the requisition for the widget. */
+void foo_scroll_area_set_min_size (FooScrollArea *scroll_area,
+ int min_width,
+ int min_height);
+
+/* Set how much of the canvas can be scrolled into view */
+void foo_scroll_area_set_size (FooScrollArea *scroll_area,
+ int width,
+ int height);
+void foo_scroll_area_set_size_fixed_y (FooScrollArea *scroll_area,
+ int width,
+ int height,
+ int old_y,
+ int new_y);
+void foo_scroll_area_set_viewport_pos (FooScrollArea *scroll_area,
+ int x,
+ int y);
+void foo_scroll_area_get_viewport (FooScrollArea *scroll_area,
+ GdkRectangle *viewport);
+void foo_scroll_area_add_input_from_stroke (FooScrollArea *scroll_area,
+ cairo_t *cr,
+ FooScrollAreaEventFunc func,
+ gpointer data);
+void foo_scroll_area_add_input_from_fill (FooScrollArea *scroll_area,
+ cairo_t *cr,
+ FooScrollAreaEventFunc func,
+ gpointer data);
+void foo_scroll_area_invalidate_region (FooScrollArea *area,
+ GdkRegion *region);
+void foo_scroll_area_invalidate (FooScrollArea *scroll_area);
+void foo_scroll_area_invalidate_rect (FooScrollArea *scroll_area,
+ int x,
+ int y,
+ int width,
+ int height);
+void foo_scroll_area_begin_grab (FooScrollArea *scroll_area,
+ FooScrollAreaEventFunc func,
+ gpointer input_data);
+void foo_scroll_area_end_grab (FooScrollArea *scroll_area);
+gboolean foo_scroll_area_is_grabbed (FooScrollArea *scroll_area);
+
+void foo_scroll_area_begin_auto_scroll (FooScrollArea *scroll_area);
+void foo_scroll_area_auto_scroll (FooScrollArea *scroll_area,
+ FooScrollAreaEvent *event);
+void foo_scroll_area_end_auto_scroll (FooScrollArea *scroll_area);
diff --git a/capplets/display/xrandr-capplet.c b/capplets/display/xrandr-capplet.c
new file mode 100644
index 00000000..94de7771
--- /dev/null
+++ b/capplets/display/xrandr-capplet.c
@@ -0,0 +1,2571 @@
+/* Monitor Settings. A preference panel for configuring monitors
+ *
+ * Copyright (C) 2007, 2008 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Soren Sandmann <[email protected]>
+ */
+
+#include <config.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+
+#include <gtk/gtk.h>
+#include "scrollarea.h"
+#define MATE_DESKTOP_USE_UNSTABLE_API
+#include <libmateui/mate-rr.h>
+#include <libmateui/mate-rr-config.h>
+#include <libmateui/mate-rr-labeler.h>
+#include <gdk/gdkx.h>
+#include <X11/Xlib.h>
+#include <glib/gi18n.h>
+#include <mateconf/mateconf-client.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-bindings.h>
+
+typedef struct App App;
+typedef struct GrabInfo GrabInfo;
+
+struct App
+{
+ MateRRScreen *screen;
+ MateRRConfig *current_configuration;
+ MateRRLabeler *labeler;
+ MateOutputInfo *current_output;
+
+ GtkWidget *dialog;
+ GtkWidget *current_monitor_event_box;
+ GtkWidget *current_monitor_label;
+ GtkWidget *monitor_on_radio;
+ GtkWidget *monitor_off_radio;
+ GtkListStore *resolution_store;
+ GtkWidget *resolution_combo;
+ GtkWidget *refresh_combo;
+ GtkWidget *rotation_combo;
+ GtkWidget *panel_checkbox;
+ GtkWidget *clone_checkbox;
+ GtkWidget *show_icon_checkbox;
+
+ /* We store the event timestamp when the Apply button is clicked */
+ GtkWidget *apply_button;
+ guint32 apply_button_clicked_timestamp;
+
+ GtkWidget *area;
+ gboolean ignore_gui_changes;
+ MateConfClient *client;
+
+ /* These are used while we are waiting for the ApplyConfiguration method to be executed over D-bus */
+ DBusGConnection *connection;
+ DBusGProxy *proxy;
+ DBusGProxyCall *proxy_call;
+
+ enum {
+ APPLYING_VERSION_1,
+ APPLYING_VERSION_2
+ } apply_configuration_state;
+};
+
+/* Response codes for custom buttons in the main dialog */
+enum {
+ RESPONSE_MAKE_DEFAULT = 1
+};
+
+static void rebuild_gui (App *app);
+static void on_clone_changed (GtkWidget *box, gpointer data);
+static void on_rate_changed (GtkComboBox *box, gpointer data);
+static gboolean output_overlaps (MateOutputInfo *output, MateRRConfig *config);
+static void select_current_output_from_dialog_position (App *app);
+static void monitor_on_off_toggled_cb (GtkToggleButton *toggle, gpointer data);
+static void get_geometry (MateOutputInfo *output, int *w, int *h);
+static void apply_configuration_returned_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, void *data);
+static gboolean get_clone_size (MateRRScreen *screen, int *width, int *height);
+static gboolean output_info_supports_mode (App *app, MateOutputInfo *info, int width, int height);
+
+static void
+error_message (App *app, const char *primary_text, const char *secondary_text)
+{
+ GtkWidget *dialog;
+
+ dialog = gtk_message_dialog_new ((app && app->dialog) ? GTK_WINDOW (app->dialog) : NULL,
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "%s", primary_text);
+
+ if (secondary_text)
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", secondary_text);
+
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+}
+
+static gboolean
+do_free (gpointer data)
+{
+ g_free (data);
+ return FALSE;
+}
+
+static gchar *
+idle_free (gchar *s)
+{
+ g_idle_add (do_free, s);
+
+ return s;
+}
+
+static void
+on_screen_changed (MateRRScreen *scr,
+ gpointer data)
+{
+ MateRRConfig *current;
+ App *app = data;
+
+ current = mate_rr_config_new_current (app->screen);
+
+ if (app->current_configuration)
+ mate_rr_config_free (app->current_configuration);
+
+ app->current_configuration = current;
+ app->current_output = NULL;
+
+ if (app->labeler) {
+ mate_rr_labeler_hide (app->labeler);
+ g_object_unref (app->labeler);
+ }
+
+ app->labeler = mate_rr_labeler_new (app->current_configuration);
+
+ select_current_output_from_dialog_position (app);
+}
+
+static void
+on_viewport_changed (FooScrollArea *scroll_area,
+ GdkRectangle *old_viewport,
+ GdkRectangle *new_viewport)
+{
+ foo_scroll_area_set_size (scroll_area,
+ new_viewport->width,
+ new_viewport->height);
+
+ foo_scroll_area_invalidate (scroll_area);
+}
+
+static void
+layout_set_font (PangoLayout *layout, const char *font)
+{
+ PangoFontDescription *desc =
+ pango_font_description_from_string (font);
+
+ if (desc)
+ {
+ pango_layout_set_font_description (layout, desc);
+
+ pango_font_description_free (desc);
+ }
+}
+
+static void
+clear_combo (GtkWidget *widget)
+{
+ GtkComboBox *box = GTK_COMBO_BOX (widget);
+ GtkTreeModel *model = gtk_combo_box_get_model (box);
+ GtkListStore *store = GTK_LIST_STORE (model);
+
+ gtk_list_store_clear (store);
+}
+
+typedef struct
+{
+ const char *text;
+ gboolean found;
+ GtkTreeIter iter;
+} ForeachInfo;
+
+static gboolean
+foreach (GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ ForeachInfo *info = data;
+ char *text = NULL;
+
+ gtk_tree_model_get (model, iter, 0, &text, -1);
+
+ g_assert (text != NULL);
+
+ if (strcmp (info->text, text) == 0)
+ {
+ info->found = TRUE;
+ info->iter = *iter;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void
+add_key (GtkWidget *widget,
+ const char *text,
+ int width, int height, int rate,
+ MateRRRotation rotation)
+{
+ ForeachInfo info;
+ GtkComboBox *box = GTK_COMBO_BOX (widget);
+ GtkTreeModel *model = gtk_combo_box_get_model (box);
+ GtkListStore *store = GTK_LIST_STORE (model);
+ gboolean retval;
+
+ info.text = text;
+ info.found = FALSE;
+
+ gtk_tree_model_foreach (model, foreach, &info);
+
+ if (!info.found)
+ {
+ GtkTreeIter iter;
+ gtk_list_store_insert_with_values (store, &iter, -1,
+ 0, text,
+ 1, width,
+ 2, height,
+ 3, rate,
+ 4, width * height,
+ 5, rotation,
+ -1);
+
+ retval = TRUE;
+ }
+ else
+ {
+ retval = FALSE;
+ }
+}
+
+static gboolean
+combo_select (GtkWidget *widget, const char *text)
+{
+ GtkComboBox *box = GTK_COMBO_BOX (widget);
+ GtkTreeModel *model = gtk_combo_box_get_model (box);
+ ForeachInfo info;
+
+ info.text = text;
+ info.found = FALSE;
+
+ gtk_tree_model_foreach (model, foreach, &info);
+
+ if (!info.found)
+ return FALSE;
+
+ gtk_combo_box_set_active_iter (box, &info.iter);
+ return TRUE;
+}
+
+static MateRRMode **
+get_current_modes (App *app)
+{
+ MateRROutput *output;
+
+ if (app->current_configuration->clone)
+ {
+ return mate_rr_screen_list_clone_modes (app->screen);
+ }
+ else
+ {
+ if (!app->current_output)
+ return NULL;
+
+ output = mate_rr_screen_get_output_by_name (
+ app->screen, app->current_output->name);
+
+ if (!output)
+ return NULL;
+
+ return mate_rr_output_list_modes (output);
+ }
+}
+
+static void
+rebuild_rotation_combo (App *app)
+{
+ typedef struct
+ {
+ MateRRRotation rotation;
+ const char * name;
+ } RotationInfo;
+ static const RotationInfo rotations[] = {
+ { MATE_RR_ROTATION_0, N_("Normal") },
+ { MATE_RR_ROTATION_90, N_("Left") },
+ { MATE_RR_ROTATION_270, N_("Right") },
+ { MATE_RR_ROTATION_180, N_("Upside Down") },
+ };
+ const char *selection;
+ MateRRRotation current;
+ int i;
+
+ clear_combo (app->rotation_combo);
+
+ gtk_widget_set_sensitive (
+ app->rotation_combo, app->current_output && app->current_output->on);
+
+ if (!app->current_output)
+ return;
+
+ current = app->current_output->rotation;
+
+ selection = NULL;
+ for (i = 0; i < G_N_ELEMENTS (rotations); ++i)
+ {
+ const RotationInfo *info = &(rotations[i]);
+
+ app->current_output->rotation = info->rotation;
+
+ /* NULL-GError --- FIXME: we should say why this rotation is not available! */
+ if (mate_rr_config_applicable (app->current_configuration, app->screen, NULL))
+ {
+ add_key (app->rotation_combo, _(info->name), 0, 0, 0, info->rotation);
+
+ if (info->rotation == current)
+ selection = _(info->name);
+ }
+ }
+
+ app->current_output->rotation = current;
+
+ if (!(selection && combo_select (app->rotation_combo, selection)))
+ combo_select (app->rotation_combo, _("Normal"));
+}
+
+static char *
+make_rate_string (int hz)
+{
+ return g_strdup_printf (_("%d Hz"), hz);
+}
+
+static void
+rebuild_rate_combo (App *app)
+{
+ GHashTable *rates;
+ MateRRMode **modes;
+ int best;
+ int i;
+
+ clear_combo (app->refresh_combo);
+
+ gtk_widget_set_sensitive (
+ app->refresh_combo, app->current_output && app->current_output->on);
+
+ if (!app->current_output
+ || !(modes = get_current_modes (app)))
+ return;
+
+ rates = g_hash_table_new_full (
+ g_str_hash, g_str_equal, (GFreeFunc) g_free, NULL);
+
+ best = -1;
+ for (i = 0; modes[i] != NULL; ++i)
+ {
+ MateRRMode *mode = modes[i];
+ int width, height, rate;
+
+ width = mate_rr_mode_get_width (mode);
+ height = mate_rr_mode_get_height (mode);
+ rate = mate_rr_mode_get_freq (mode);
+
+ if (width == app->current_output->width &&
+ height == app->current_output->height)
+ {
+ add_key (app->refresh_combo,
+ idle_free (make_rate_string (rate)),
+ 0, 0, rate, -1);
+
+ if (rate > best)
+ best = rate;
+ }
+ }
+
+ if (!combo_select (app->refresh_combo, idle_free (make_rate_string (app->current_output->rate))))
+ combo_select (app->refresh_combo, idle_free (make_rate_string (best)));
+}
+
+static int
+count_active_outputs (App *app)
+{
+ int i, count = 0;
+
+ for (i = 0; app->current_configuration->outputs[i] != NULL; ++i)
+ {
+ MateOutputInfo *output = app->current_configuration->outputs[i];
+ if (output->on)
+ count++;
+ }
+
+ return count;
+}
+
+#if 0
+static int
+count_all_outputs (MateRRConfig *config)
+{
+ int i;
+
+ for (i = 0; config->outputs[i] != NULL; i++)
+ ;
+
+ return i;
+}
+#endif
+
+/* Computes whether "Mirror Screens" (clone mode) is supported based on these criteria:
+ *
+ * 1. There is an available size for cloning.
+ *
+ * 2. There are 2 or more connected outputs that support that size.
+ */
+static gboolean
+mirror_screens_is_supported (App *app)
+{
+ int clone_width, clone_height;
+ gboolean have_clone_size;
+ gboolean mirror_is_supported;
+
+ mirror_is_supported = FALSE;
+
+ have_clone_size = get_clone_size (app->screen, &clone_width, &clone_height);
+
+ if (have_clone_size) {
+ int i;
+ int num_outputs_with_clone_size;
+
+ num_outputs_with_clone_size = 0;
+
+ for (i = 0; app->current_configuration->outputs[i] != NULL; i++)
+ {
+ MateOutputInfo *output = app->current_configuration->outputs[i];
+
+ /* We count the connected outputs that support the clone size. It
+ * doesn't matter if those outputs aren't actually On currently; we
+ * will turn them on in on_clone_changed().
+ */
+ if (output->connected && output_info_supports_mode (app, output, clone_width, clone_height))
+ num_outputs_with_clone_size++;
+ }
+
+ if (num_outputs_with_clone_size >= 2)
+ mirror_is_supported = TRUE;
+ }
+
+ return mirror_is_supported;
+}
+
+static void
+rebuild_mirror_screens (App *app)
+{
+ gboolean mirror_is_active;
+ gboolean mirror_is_supported;
+
+ g_signal_handlers_block_by_func (app->clone_checkbox, G_CALLBACK (on_clone_changed), app);
+
+ mirror_is_active = app->current_configuration && app->current_configuration->clone;
+
+ /* If mirror_is_active, then it *must* be possible to turn mirroring off */
+ mirror_is_supported = mirror_is_active || mirror_screens_is_supported (app);
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->clone_checkbox), mirror_is_active);
+ gtk_widget_set_sensitive (app->clone_checkbox, mirror_is_supported);
+
+ g_signal_handlers_unblock_by_func (app->clone_checkbox, G_CALLBACK (on_clone_changed), app);
+}
+
+static void
+rebuild_current_monitor_label (App *app)
+{
+ char *str, *tmp;
+ GdkColor color;
+ gboolean use_color;
+
+ if (app->current_output)
+ {
+ if (app->current_configuration->clone)
+ tmp = g_strdup (_("Mirror Screens"));
+ else
+ tmp = g_strdup_printf (_("Monitor: %s"), app->current_output->display_name);
+
+ str = g_strdup_printf ("<b>%s</b>", tmp);
+ mate_rr_labeler_get_color_for_output (app->labeler, app->current_output, &color);
+ use_color = TRUE;
+ g_free (tmp);
+ }
+ else
+ {
+ str = g_strdup_printf ("<b>%s</b>", _("Monitor"));
+ use_color = FALSE;
+ }
+
+ gtk_label_set_markup (GTK_LABEL (app->current_monitor_label), str);
+ g_free (str);
+
+ if (use_color)
+ {
+ GdkColor black = { 0, 0, 0, 0 };
+
+ gtk_widget_modify_bg (app->current_monitor_event_box, gtk_widget_get_state (app->current_monitor_event_box), &color);
+
+ /* Make the label explicitly black. We don't want it to follow the
+ * theme's colors, since the label is always shown against a light
+ * pastel background. See bgo#556050
+ */
+ gtk_widget_modify_fg (app->current_monitor_label, gtk_widget_get_state (app->current_monitor_label), &black);
+ }
+ else
+ {
+ /* Remove any modifications we did on the label's color */
+ GtkRcStyle *reset_rc_style;
+
+ reset_rc_style = gtk_rc_style_new ();
+ gtk_widget_modify_style (app->current_monitor_label, reset_rc_style); /* takes ownership of, and destroys, the rc style */
+ }
+
+ gtk_event_box_set_visible_window (GTK_EVENT_BOX (app->current_monitor_event_box), use_color);
+}
+
+static void
+rebuild_on_off_radios (App *app)
+{
+ gboolean sensitive;
+ gboolean on_active;
+ gboolean off_active;
+
+ g_signal_handlers_block_by_func (app->monitor_on_radio, G_CALLBACK (monitor_on_off_toggled_cb), app);
+ g_signal_handlers_block_by_func (app->monitor_off_radio, G_CALLBACK (monitor_on_off_toggled_cb), app);
+
+ sensitive = FALSE;
+ on_active = FALSE;
+ off_active = FALSE;
+
+ if (!app->current_configuration->clone && app->current_output)
+ {
+ if (count_active_outputs (app) > 1 || !app->current_output->on)
+ sensitive = TRUE;
+ else
+ sensitive = FALSE;
+
+ on_active = app->current_output->on;
+ off_active = !on_active;
+ }
+
+ gtk_widget_set_sensitive (app->monitor_on_radio, sensitive);
+ gtk_widget_set_sensitive (app->monitor_off_radio, sensitive);
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->monitor_on_radio), on_active);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->monitor_off_radio), off_active);
+
+ g_signal_handlers_unblock_by_func (app->monitor_on_radio, G_CALLBACK (monitor_on_off_toggled_cb), app);
+ g_signal_handlers_unblock_by_func (app->monitor_off_radio, G_CALLBACK (monitor_on_off_toggled_cb), app);
+}
+
+static char *
+make_resolution_string (int width, int height)
+{
+ return g_strdup_printf (_("%d x %d"), width, height);
+}
+
+static void
+find_best_mode (MateRRMode **modes, int *out_width, int *out_height)
+{
+ int i;
+
+ *out_width = 0;
+ *out_height = 0;
+
+ for (i = 0; modes[i] != NULL; i++)
+ {
+ int w, h;
+
+ w = mate_rr_mode_get_width (modes[i]);
+ h = mate_rr_mode_get_height (modes[i]);
+
+ if (w * h > *out_width * *out_height)
+ {
+ *out_width = w;
+ *out_height = h;
+ }
+ }
+}
+
+static void
+rebuild_resolution_combo (App *app)
+{
+ int i;
+ MateRRMode **modes;
+ const char *current;
+
+ clear_combo (app->resolution_combo);
+
+ if (!(modes = get_current_modes (app))
+ || !app->current_output
+ || !app->current_output->on)
+ {
+ gtk_widget_set_sensitive (app->resolution_combo, FALSE);
+ return;
+ }
+
+ g_assert (app->current_output != NULL);
+ g_assert (app->current_output->width != 0 && app->current_output->height != 0);
+
+ gtk_widget_set_sensitive (app->resolution_combo, TRUE);
+
+ for (i = 0; modes[i] != NULL; ++i)
+ {
+ int width, height;
+
+ width = mate_rr_mode_get_width (modes[i]);
+ height = mate_rr_mode_get_height (modes[i]);
+
+ add_key (app->resolution_combo,
+ idle_free (make_resolution_string (width, height)),
+ width, height, 0, -1);
+ }
+
+ current = idle_free (make_resolution_string (app->current_output->width, app->current_output->height));
+
+ if (!combo_select (app->resolution_combo, current))
+ {
+ int best_w, best_h;
+
+ find_best_mode (modes, &best_w, &best_h);
+ combo_select (app->resolution_combo, idle_free (make_resolution_string (best_w, best_h)));
+ }
+}
+
+static void
+rebuild_gui (App *app)
+{
+ gboolean sensitive;
+
+ /* We would break spectacularly if we recursed, so
+ * just assert if that happens
+ */
+ g_assert (app->ignore_gui_changes == FALSE);
+
+ app->ignore_gui_changes = TRUE;
+
+ sensitive = app->current_output ? TRUE : FALSE;
+
+#if 0
+ g_debug ("rebuild gui, is on: %d", app->current_output->on);
+#endif
+
+ rebuild_mirror_screens (app);
+ rebuild_current_monitor_label (app);
+ rebuild_on_off_radios (app);
+ rebuild_resolution_combo (app);
+ rebuild_rate_combo (app);
+ rebuild_rotation_combo (app);
+
+#if 0
+ g_debug ("sensitive: %d, on: %d", sensitive, app->current_output->on);
+#endif
+ gtk_widget_set_sensitive (app->panel_checkbox, sensitive);
+
+ app->ignore_gui_changes = FALSE;
+}
+
+static gboolean
+get_mode (GtkWidget *widget, int *width, int *height, int *freq, MateRRRotation *rot)
+{
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ GtkComboBox *box = GTK_COMBO_BOX (widget);
+ int dummy;
+
+ if (!gtk_combo_box_get_active_iter (box, &iter))
+ return FALSE;
+
+ if (!width)
+ width = &dummy;
+
+ if (!height)
+ height = &dummy;
+
+ if (!freq)
+ freq = &dummy;
+
+ if (!rot)
+ rot = (MateRRRotation *)&dummy;
+
+ model = gtk_combo_box_get_model (box);
+ gtk_tree_model_get (model, &iter,
+ 1, width,
+ 2, height,
+ 3, freq,
+ 5, rot,
+ -1);
+
+ return TRUE;
+
+}
+
+static void
+on_rotation_changed (GtkComboBox *box, gpointer data)
+{
+ App *app = data;
+ MateRRRotation rotation;
+
+ if (!app->current_output)
+ return;
+
+ if (get_mode (app->rotation_combo, NULL, NULL, NULL, &rotation))
+ app->current_output->rotation = rotation;
+
+ foo_scroll_area_invalidate (FOO_SCROLL_AREA (app->area));
+}
+
+static void
+on_rate_changed (GtkComboBox *box, gpointer data)
+{
+ App *app = data;
+ int rate;
+
+ if (!app->current_output)
+ return;
+
+ if (get_mode (app->refresh_combo, NULL, NULL, &rate, NULL))
+ app->current_output->rate = rate;
+
+ foo_scroll_area_invalidate (FOO_SCROLL_AREA (app->area));
+}
+
+static void
+select_resolution_for_current_output (App *app)
+{
+ MateRRMode **modes;
+ int width, height;
+
+ if (app->current_output->pref_width != 0 && app->current_output->pref_height != 0)
+ {
+ app->current_output->width = app->current_output->pref_width;
+ app->current_output->height = app->current_output->pref_height;
+ return;
+ }
+
+ modes = get_current_modes (app);
+ if (!modes)
+ return;
+
+ find_best_mode (modes, &width, &height);
+
+ app->current_output->width = width;
+ app->current_output->height = height;
+}
+
+static void
+monitor_on_off_toggled_cb (GtkToggleButton *toggle, gpointer data)
+{
+ App *app = data;
+ gboolean is_on;
+
+ if (!app->current_output)
+ return;
+
+ if (!gtk_toggle_button_get_active (toggle))
+ return;
+
+ if (GTK_WIDGET (toggle) == app->monitor_on_radio)
+ is_on = TRUE;
+ else if (GTK_WIDGET (toggle) == app->monitor_off_radio)
+ is_on = FALSE;
+ else
+ {
+ g_assert_not_reached ();
+ return;
+ }
+
+ app->current_output->on = is_on;
+
+ if (is_on)
+ select_resolution_for_current_output (app); /* The refresh rate will be picked in rebuild_rate_combo() */
+
+ rebuild_gui (app);
+ foo_scroll_area_invalidate (FOO_SCROLL_AREA (app->area));
+}
+
+static void
+realign_outputs_after_resolution_change (App *app, MateOutputInfo *output_that_changed, int old_width, int old_height)
+{
+ /* We find the outputs that were below or to the right of the output that
+ * changed, and realign them; we also do that for outputs that shared the
+ * right/bottom edges with the output that changed. The outputs that are
+ * above or to the left of that output don't need to change.
+ */
+
+ int i;
+ int old_right_edge, old_bottom_edge;
+ int dx, dy;
+
+ g_assert (app->current_configuration != NULL);
+
+ if (output_that_changed->width == old_width && output_that_changed->height == old_height)
+ return;
+
+ old_right_edge = output_that_changed->x + old_width;
+ old_bottom_edge = output_that_changed->y + old_height;
+
+ dx = output_that_changed->width - old_width;
+ dy = output_that_changed->height - old_height;
+
+ for (i = 0; app->current_configuration->outputs[i] != NULL; i++) {
+ MateOutputInfo *output;
+ int output_width, output_height;
+
+ output = app->current_configuration->outputs[i];
+
+ if (output == output_that_changed || !output->connected)
+ continue;
+
+ get_geometry (output, &output_width, &output_height);
+
+ if (output->x >= old_right_edge)
+ output->x += dx;
+ else if (output->x + output_width == old_right_edge)
+ output->x = output_that_changed->x + output_that_changed->width - output_width;
+
+ if (output->y >= old_bottom_edge)
+ output->y += dy;
+ else if (output->y + output_height == old_bottom_edge)
+ output->y = output_that_changed->y + output_that_changed->height - output_height;
+ }
+}
+
+static void
+on_resolution_changed (GtkComboBox *box, gpointer data)
+{
+ App *app = data;
+ int old_width, old_height;
+ int width;
+ int height;
+
+ if (!app->current_output)
+ return;
+
+ old_width = app->current_output->width;
+ old_height = app->current_output->height;
+
+ if (get_mode (app->resolution_combo, &width, &height, NULL, NULL))
+ {
+ app->current_output->width = width;
+ app->current_output->height = height;
+
+ if (width == 0 || height == 0)
+ app->current_output->on = FALSE;
+ else
+ app->current_output->on = TRUE;
+ }
+
+ realign_outputs_after_resolution_change (app, app->current_output, old_width, old_height);
+
+ rebuild_rate_combo (app);
+ rebuild_rotation_combo (app);
+
+ foo_scroll_area_invalidate (FOO_SCROLL_AREA (app->area));
+}
+
+static void
+lay_out_outputs_horizontally (App *app)
+{
+ int i;
+ int x;
+
+ /* Lay out all the monitors horizontally when "mirror screens" is turned
+ * off, to avoid having all of them overlapped initially. We put the
+ * outputs turned off on the right-hand side.
+ */
+
+ x = 0;
+
+ /* First pass, all "on" outputs */
+
+ for (i = 0; app->current_configuration->outputs[i]; ++i)
+ {
+ MateOutputInfo *output;
+
+ output = app->current_configuration->outputs[i];
+ if (output->connected && output->on) {
+ output->x = x;
+ output->y = 0;
+ x += output->width;
+ }
+ }
+
+ /* Second pass, all the black screens */
+
+ for (i = 0; app->current_configuration->outputs[i]; ++i)
+ {
+ MateOutputInfo *output;
+
+ output = app->current_configuration->outputs[i];
+ if (!(output->connected && output->on)) {
+ output->x = x;
+ output->y = 0;
+ x += output->width;
+ }
+ }
+
+}
+
+/* FIXME: this function is copied from mate-settings-daemon/plugins/xrandr/gsd-xrandr-manager.c.
+ * Do we need to put this function in mate-desktop for public use?
+ */
+static gboolean
+get_clone_size (MateRRScreen *screen, int *width, int *height)
+{
+ MateRRMode **modes = mate_rr_screen_list_clone_modes (screen);
+ int best_w, best_h;
+ int i;
+
+ best_w = 0;
+ best_h = 0;
+
+ for (i = 0; modes[i] != NULL; ++i) {
+ MateRRMode *mode = modes[i];
+ int w, h;
+
+ w = mate_rr_mode_get_width (mode);
+ h = mate_rr_mode_get_height (mode);
+
+ if (w * h > best_w * best_h) {
+ best_w = w;
+ best_h = h;
+ }
+ }
+
+ if (best_w > 0 && best_h > 0) {
+ if (width)
+ *width = best_w;
+ if (height)
+ *height = best_h;
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static gboolean
+output_info_supports_mode (App *app, MateOutputInfo *info, int width, int height)
+{
+ MateRROutput *output;
+ MateRRMode **modes;
+ int i;
+
+ if (!info->connected)
+ return FALSE;
+
+ output = mate_rr_screen_get_output_by_name (app->screen, info->name);
+ if (!output)
+ return FALSE;
+
+ modes = mate_rr_output_list_modes (output);
+
+ for (i = 0; modes[i]; i++) {
+ if (mate_rr_mode_get_width (modes[i]) == width
+ && mate_rr_mode_get_height (modes[i]) == height)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void
+on_clone_changed (GtkWidget *box, gpointer data)
+{
+ App *app = data;
+
+ app->current_configuration->clone =
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (app->clone_checkbox));
+
+ if (app->current_configuration->clone)
+ {
+ int i;
+ int width, height;
+
+ for (i = 0; app->current_configuration->outputs[i]; ++i)
+ {
+ if (app->current_configuration->outputs[i]->connected)
+ {
+ app->current_output = app->current_configuration->outputs[i];
+ break;
+ }
+ }
+
+ /* Turn on all the connected screens that support the best clone mode.
+ * The user may hit "Mirror Screens", but he shouldn't have to turn on
+ * all the required outputs as well.
+ */
+
+ get_clone_size (app->screen, &width, &height);
+
+ for (i = 0; app->current_configuration->outputs[i]; i++) {
+ if (output_info_supports_mode (app, app->current_configuration->outputs[i], width, height)) {
+ app->current_configuration->outputs[i]->on = TRUE;
+ app->current_configuration->outputs[i]->width = width;
+ app->current_configuration->outputs[i]->height = height;
+ }
+ }
+ }
+ else
+ {
+ if (output_overlaps (app->current_output, app->current_configuration))
+ lay_out_outputs_horizontally (app);
+ }
+
+ rebuild_gui (app);
+}
+
+static void
+get_geometry (MateOutputInfo *output, int *w, int *h)
+{
+ if (output->on)
+ {
+ *h = output->height;
+ *w = output->width;
+ }
+ else
+ {
+ *h = output->pref_height;
+ *w = output->pref_width;
+ }
+ if ((output->rotation & MATE_RR_ROTATION_90) || (output->rotation & MATE_RR_ROTATION_270))
+ {
+ int tmp;
+ tmp = *h;
+ *h = *w;
+ *w = tmp;
+ }
+}
+
+#define SPACE 15
+#define MARGIN 15
+
+static GList *
+list_connected_outputs (App *app, int *total_w, int *total_h)
+{
+ int i, dummy;
+ GList *result = NULL;
+
+ if (!total_w)
+ total_w = &dummy;
+ if (!total_h)
+ total_h = &dummy;
+
+ *total_w = 0;
+ *total_h = 0;
+ for (i = 0; app->current_configuration->outputs[i] != NULL; ++i)
+ {
+ MateOutputInfo *output = app->current_configuration->outputs[i];
+
+ if (output->connected)
+ {
+ int w, h;
+
+ result = g_list_prepend (result, output);
+
+ get_geometry (output, &w, &h);
+
+ *total_w += w;
+ *total_h += h;
+ }
+ }
+
+ return g_list_reverse (result);
+}
+
+static int
+get_n_connected (App *app)
+{
+ GList *connected_outputs = list_connected_outputs (app, NULL, NULL);
+ int n = g_list_length (connected_outputs);
+
+ g_list_free (connected_outputs);
+
+ return n;
+}
+
+static double
+compute_scale (App *app)
+{
+ int available_w, available_h;
+ int total_w, total_h;
+ int n_monitors;
+ GdkRectangle viewport;
+ GList *connected_outputs;
+
+ foo_scroll_area_get_viewport (FOO_SCROLL_AREA (app->area), &viewport);
+
+ connected_outputs = list_connected_outputs (app, &total_w, &total_h);
+
+ n_monitors = g_list_length (connected_outputs);
+
+ g_list_free (connected_outputs);
+
+ available_w = viewport.width - 2 * MARGIN - (n_monitors - 1) * SPACE;
+ available_h = viewport.height - 2 * MARGIN - (n_monitors - 1) * SPACE;
+
+ return MIN ((double)available_w / total_w, (double)available_h / total_h);
+}
+
+typedef struct Edge
+{
+ MateOutputInfo *output;
+ int x1, y1;
+ int x2, y2;
+} Edge;
+
+typedef struct Snap
+{
+ Edge *snapper; /* Edge that should be snapped */
+ Edge *snappee;
+ int dy, dx;
+} Snap;
+
+static void
+add_edge (MateOutputInfo *output, int x1, int y1, int x2, int y2, GArray *edges)
+{
+ Edge e;
+
+ e.x1 = x1;
+ e.x2 = x2;
+ e.y1 = y1;
+ e.y2 = y2;
+ e.output = output;
+
+ g_array_append_val (edges, e);
+}
+
+static void
+list_edges_for_output (MateOutputInfo *output, GArray *edges)
+{
+ int x, y, w, h;
+
+ x = output->x;
+ y = output->y;
+ get_geometry (output, &w, &h);
+
+ /* Top, Bottom, Left, Right */
+ add_edge (output, x, y, x + w, y, edges);
+ add_edge (output, x, y + h, x + w, y + h, edges);
+ add_edge (output, x, y, x, y + h, edges);
+ add_edge (output, x + w, y, x + w, y + h, edges);
+}
+
+static void
+list_edges (MateRRConfig *config, GArray *edges)
+{
+ int i;
+
+ for (i = 0; config->outputs[i]; ++i)
+ {
+ MateOutputInfo *output = config->outputs[i];
+
+ if (output->connected)
+ list_edges_for_output (output, edges);
+ }
+}
+
+static gboolean
+overlap (int s1, int e1, int s2, int e2)
+{
+ return (!(e1 < s2 || s1 >= e2));
+}
+
+static gboolean
+horizontal_overlap (Edge *snapper, Edge *snappee)
+{
+ if (snapper->y1 != snapper->y2 || snappee->y1 != snappee->y2)
+ return FALSE;
+
+ return overlap (snapper->x1, snapper->x2, snappee->x1, snappee->x2);
+}
+
+static gboolean
+vertical_overlap (Edge *snapper, Edge *snappee)
+{
+ if (snapper->x1 != snapper->x2 || snappee->x1 != snappee->x2)
+ return FALSE;
+
+ return overlap (snapper->y1, snapper->y2, snappee->y1, snappee->y2);
+}
+
+static void
+add_snap (GArray *snaps, Snap snap)
+{
+ if (ABS (snap.dx) <= 200 || ABS (snap.dy) <= 200)
+ g_array_append_val (snaps, snap);
+}
+
+static void
+add_edge_snaps (Edge *snapper, Edge *snappee, GArray *snaps)
+{
+ Snap snap;
+
+ snap.snapper = snapper;
+ snap.snappee = snappee;
+
+ if (horizontal_overlap (snapper, snappee))
+ {
+ snap.dx = 0;
+ snap.dy = snappee->y1 - snapper->y1;
+
+ add_snap (snaps, snap);
+ }
+ else if (vertical_overlap (snapper, snappee))
+ {
+ snap.dy = 0;
+ snap.dx = snappee->x1 - snapper->x1;
+
+ add_snap (snaps, snap);
+ }
+
+ /* Corner snaps */
+ /* 1->1 */
+ snap.dx = snappee->x1 - snapper->x1;
+ snap.dy = snappee->y1 - snapper->y1;
+
+ add_snap (snaps, snap);
+
+ /* 1->2 */
+ snap.dx = snappee->x2 - snapper->x1;
+ snap.dy = snappee->y2 - snapper->y1;
+
+ add_snap (snaps, snap);
+
+ /* 2->2 */
+ snap.dx = snappee->x2 - snapper->x2;
+ snap.dy = snappee->y2 - snapper->y2;
+
+ add_snap (snaps, snap);
+
+ /* 2->1 */
+ snap.dx = snappee->x1 - snapper->x2;
+ snap.dy = snappee->y1 - snapper->y2;
+
+ add_snap (snaps, snap);
+}
+
+static void
+list_snaps (MateOutputInfo *output, GArray *edges, GArray *snaps)
+{
+ int i;
+
+ for (i = 0; i < edges->len; ++i)
+ {
+ Edge *output_edge = &(g_array_index (edges, Edge, i));
+
+ if (output_edge->output == output)
+ {
+ int j;
+
+ for (j = 0; j < edges->len; ++j)
+ {
+ Edge *edge = &(g_array_index (edges, Edge, j));
+
+ if (edge->output != output)
+ add_edge_snaps (output_edge, edge, snaps);
+ }
+ }
+ }
+}
+
+#if 0
+static void
+print_edge (Edge *edge)
+{
+ g_debug ("(%d %d %d %d)", edge->x1, edge->y1, edge->x2, edge->y2);
+}
+#endif
+
+static gboolean
+corner_on_edge (int x, int y, Edge *e)
+{
+ if (x == e->x1 && x == e->x2 && y >= e->y1 && y <= e->y2)
+ return TRUE;
+
+ if (y == e->y1 && y == e->y2 && x >= e->x1 && x <= e->x2)
+ return TRUE;
+
+ return FALSE;
+}
+
+static gboolean
+edges_align (Edge *e1, Edge *e2)
+{
+ if (corner_on_edge (e1->x1, e1->y1, e2))
+ return TRUE;
+
+ if (corner_on_edge (e2->x1, e2->y1, e1))
+ return TRUE;
+
+ return FALSE;
+}
+
+static gboolean
+output_is_aligned (MateOutputInfo *output, GArray *edges)
+{
+ gboolean result = FALSE;
+ int i;
+
+ for (i = 0; i < edges->len; ++i)
+ {
+ Edge *output_edge = &(g_array_index (edges, Edge, i));
+
+ if (output_edge->output == output)
+ {
+ int j;
+
+ for (j = 0; j < edges->len; ++j)
+ {
+ Edge *edge = &(g_array_index (edges, Edge, j));
+
+ /* We are aligned if an output edge matches
+ * an edge of another output
+ */
+ if (edge->output != output_edge->output)
+ {
+ if (edges_align (output_edge, edge))
+ {
+ result = TRUE;
+ goto done;
+ }
+ }
+ }
+ }
+ }
+done:
+
+ return result;
+}
+
+static void
+get_output_rect (MateOutputInfo *output, GdkRectangle *rect)
+{
+ int w, h;
+
+ get_geometry (output, &w, &h);
+
+ rect->width = w;
+ rect->height = h;
+ rect->x = output->x;
+ rect->y = output->y;
+}
+
+static gboolean
+output_overlaps (MateOutputInfo *output, MateRRConfig *config)
+{
+ int i;
+ GdkRectangle output_rect;
+
+ get_output_rect (output, &output_rect);
+
+ for (i = 0; config->outputs[i]; ++i)
+ {
+ MateOutputInfo *other = config->outputs[i];
+
+ if (other != output && other->connected)
+ {
+ GdkRectangle other_rect;
+
+ get_output_rect (other, &other_rect);
+ if (gdk_rectangle_intersect (&output_rect, &other_rect, NULL))
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+static gboolean
+mate_rr_config_is_aligned (MateRRConfig *config, GArray *edges)
+{
+ int i;
+ gboolean result = TRUE;
+
+ for (i = 0; config->outputs[i]; ++i)
+ {
+ MateOutputInfo *output = config->outputs[i];
+
+ if (output->connected)
+ {
+ if (!output_is_aligned (output, edges))
+ return FALSE;
+
+ if (output_overlaps (output, config))
+ return FALSE;
+ }
+ }
+
+ return result;
+}
+
+struct GrabInfo
+{
+ int grab_x;
+ int grab_y;
+ int output_x;
+ int output_y;
+};
+
+static gboolean
+is_corner_snap (const Snap *s)
+{
+ return s->dx != 0 && s->dy != 0;
+}
+
+static int
+compare_snaps (gconstpointer v1, gconstpointer v2)
+{
+ const Snap *s1 = v1;
+ const Snap *s2 = v2;
+ int sv1 = MAX (ABS (s1->dx), ABS (s1->dy));
+ int sv2 = MAX (ABS (s2->dx), ABS (s2->dy));
+ int d;
+
+ d = sv1 - sv2;
+
+ /* This snapping algorithm is good enough for rock'n'roll, but
+ * this is probably a better:
+ *
+ * First do a horizontal/vertical snap, then
+ * with the new coordinates from that snap,
+ * do a corner snap.
+ *
+ * Right now, it's confusing that corner snapping
+ * depends on the distance in an axis that you can't actually see.
+ *
+ */
+ if (d == 0)
+ {
+ if (is_corner_snap (s1) && !is_corner_snap (s2))
+ return -1;
+ else if (is_corner_snap (s2) && !is_corner_snap (s1))
+ return 1;
+ else
+ return 0;
+ }
+ else
+ {
+ return d;
+ }
+}
+
+/* Sets a mouse cursor for a widget's window. As a hack, you can pass
+ * GDK_BLANK_CURSOR to mean "set the cursor to NULL" (i.e. reset the widget's
+ * window's cursor to its default).
+ */
+static void
+set_cursor (GtkWidget *widget, GdkCursorType type)
+{
+ GdkCursor *cursor;
+ GdkWindow *window;
+
+ if (type == GDK_BLANK_CURSOR)
+ cursor = NULL;
+ else
+ cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), type);
+
+ window = gtk_widget_get_window (widget);
+
+ if (window)
+ gdk_window_set_cursor (window, cursor);
+
+ if (cursor)
+ gdk_cursor_unref (cursor);
+}
+
+static void
+set_monitors_tooltip (App *app, gboolean is_dragging)
+{
+ const char *text;
+
+ if (is_dragging)
+ text = NULL;
+ else
+ text = _("Select a monitor to change its properties; drag it to rearrange its placement.");
+
+ gtk_widget_set_tooltip_text (app->area, text);
+}
+
+static void
+on_output_event (FooScrollArea *area,
+ FooScrollAreaEvent *event,
+ gpointer data)
+{
+ MateOutputInfo *output = data;
+ App *app = g_object_get_data (G_OBJECT (area), "app");
+
+ /* If the mouse is inside the outputs, set the cursor to "you can move me". See
+ * on_canvas_event() for where we reset the cursor to the default if it
+ * exits the outputs' area.
+ */
+ if (!app->current_configuration->clone && get_n_connected (app) > 1)
+ set_cursor (GTK_WIDGET (area), GDK_FLEUR);
+
+ if (event->type == FOO_BUTTON_PRESS)
+ {
+ GrabInfo *info;
+
+ app->current_output = output;
+
+ rebuild_gui (app);
+ set_monitors_tooltip (app, TRUE);
+
+ if (!app->current_configuration->clone && get_n_connected (app) > 1)
+ {
+ foo_scroll_area_begin_grab (area, on_output_event, data);
+
+ info = g_new0 (GrabInfo, 1);
+ info->grab_x = event->x;
+ info->grab_y = event->y;
+ info->output_x = output->x;
+ info->output_y = output->y;
+
+ output->user_data = info;
+ }
+
+ foo_scroll_area_invalidate (area);
+ }
+ else
+ {
+ if (foo_scroll_area_is_grabbed (area))
+ {
+ GrabInfo *info = output->user_data;
+ double scale = compute_scale (app);
+ int old_x, old_y;
+ int new_x, new_y;
+ int i;
+ GArray *edges, *snaps, *new_edges;
+
+ old_x = output->x;
+ old_y = output->y;
+ new_x = info->output_x + (event->x - info->grab_x) / scale;
+ new_y = info->output_y + (event->y - info->grab_y) / scale;
+
+ output->x = new_x;
+ output->y = new_y;
+
+ edges = g_array_new (TRUE, TRUE, sizeof (Edge));
+ snaps = g_array_new (TRUE, TRUE, sizeof (Snap));
+ new_edges = g_array_new (TRUE, TRUE, sizeof (Edge));
+
+ list_edges (app->current_configuration, edges);
+ list_snaps (output, edges, snaps);
+
+ g_array_sort (snaps, compare_snaps);
+
+ output->x = info->output_x;
+ output->y = info->output_y;
+
+ for (i = 0; i < snaps->len; ++i)
+ {
+ Snap *snap = &(g_array_index (snaps, Snap, i));
+ GArray *new_edges = g_array_new (TRUE, TRUE, sizeof (Edge));
+
+ output->x = new_x + snap->dx;
+ output->y = new_y + snap->dy;
+
+ g_array_set_size (new_edges, 0);
+ list_edges (app->current_configuration, new_edges);
+
+ if (mate_rr_config_is_aligned (app->current_configuration, new_edges))
+ {
+ g_array_free (new_edges, TRUE);
+ break;
+ }
+ else
+ {
+ output->x = info->output_x;
+ output->y = info->output_y;
+ }
+ }
+
+ g_array_free (new_edges, TRUE);
+ g_array_free (snaps, TRUE);
+ g_array_free (edges, TRUE);
+
+ if (event->type == FOO_BUTTON_RELEASE)
+ {
+ foo_scroll_area_end_grab (area);
+ set_monitors_tooltip (app, FALSE);
+
+ g_free (output->user_data);
+ output->user_data = NULL;
+
+#if 0
+ g_debug ("new position: %d %d %d %d", output->x, output->y, output->width, output->height);
+#endif
+ }
+
+ foo_scroll_area_invalidate (area);
+ }
+ }
+}
+
+static void
+on_canvas_event (FooScrollArea *area,
+ FooScrollAreaEvent *event,
+ gpointer data)
+{
+ /* If the mouse exits the outputs, reset the cursor to the default. See
+ * on_output_event() for where we set the cursor to the movement cursor if
+ * it is over one of the outputs.
+ */
+ set_cursor (GTK_WIDGET (area), GDK_BLANK_CURSOR);
+}
+
+static PangoLayout *
+get_display_name (App *app,
+ MateOutputInfo *output)
+{
+ const char *text;
+
+ if (app->current_configuration->clone) {
+ /* Translators: this is the feature where what you see on your laptop's
+ * screen is the same as your external monitor. Here, "Mirror" is being
+ * used as an adjective, not as a verb. For example, the Spanish
+ * translation could be "Pantallas en Espejo", *not* "Espejar Pantallas".
+ */
+ text = _("Mirror Screens");
+ } else
+ text = output->display_name;
+
+ return gtk_widget_create_pango_layout (
+ GTK_WIDGET (app->area), text);
+}
+
+static void
+paint_background (FooScrollArea *area,
+ cairo_t *cr)
+{
+ GdkRectangle viewport;
+ GtkWidget *widget;
+ GtkStyle *widget_style;
+
+ widget = GTK_WIDGET (area);
+
+ foo_scroll_area_get_viewport (area, &viewport);
+ widget_style = gtk_widget_get_style (widget);
+
+ cairo_set_source_rgb (cr,
+ widget_style->base[GTK_STATE_SELECTED].red / 65535.0,
+ widget_style->base[GTK_STATE_SELECTED].green / 65535.0,
+ widget_style->base[GTK_STATE_SELECTED].blue / 65535.0);
+
+ cairo_rectangle (cr,
+ viewport.x, viewport.y,
+ viewport.width, viewport.height);
+
+ cairo_fill_preserve (cr);
+
+ foo_scroll_area_add_input_from_fill (area, cr, on_canvas_event, NULL);
+
+ cairo_set_source_rgb (cr,
+ widget_style->dark[GTK_STATE_SELECTED].red / 65535.0,
+ widget_style->dark[GTK_STATE_SELECTED].green / 65535.0,
+ widget_style->dark[GTK_STATE_SELECTED].blue / 65535.0);
+
+ cairo_stroke (cr);
+}
+
+static void
+paint_output (App *app, cairo_t *cr, int i)
+{
+ int w, h;
+ double scale = compute_scale (app);
+ double x, y;
+ int total_w, total_h;
+ GList *connected_outputs = list_connected_outputs (app, &total_w, &total_h);
+ MateOutputInfo *output = g_list_nth (connected_outputs, i)->data;
+ PangoLayout *layout = get_display_name (app, output);
+ PangoRectangle ink_extent, log_extent;
+ GdkRectangle viewport;
+ GdkColor output_color;
+ double r, g, b;
+ double available_w;
+ double factor;
+
+ cairo_save (cr);
+
+ foo_scroll_area_get_viewport (FOO_SCROLL_AREA (app->area), &viewport);
+
+ get_geometry (output, &w, &h);
+
+#if 0
+ g_debug ("%s (%p) geometry %d %d %d", output->name, output,
+ w, h, output->rate);
+#endif
+
+ viewport.height -= 2 * MARGIN;
+ viewport.width -= 2 * MARGIN;
+
+ x = output->x * scale + MARGIN + (viewport.width - total_w * scale) / 2.0;
+ y = output->y * scale + MARGIN + (viewport.height - total_h * scale) / 2.0;
+
+#if 0
+ g_debug ("scaled: %f %f", x, y);
+
+ g_debug ("scale: %f", scale);
+
+ g_debug ("%f %f %f %f", x, y, w * scale + 0.5, h * scale + 0.5);
+#endif
+
+ cairo_save (cr);
+
+ cairo_translate (cr,
+ x + (w * scale + 0.5) / 2,
+ y + (h * scale + 0.5) / 2);
+
+ /* rotation is already applied in get_geometry */
+
+ if (output->rotation & MATE_RR_REFLECT_X)
+ cairo_scale (cr, -1, 1);
+
+ if (output->rotation & MATE_RR_REFLECT_Y)
+ cairo_scale (cr, 1, -1);
+
+ cairo_translate (cr,
+ - x - (w * scale + 0.5) / 2,
+ - y - (h * scale + 0.5) / 2);
+
+
+ cairo_rectangle (cr, x, y, w * scale + 0.5, h * scale + 0.5);
+ cairo_clip_preserve (cr);
+
+ mate_rr_labeler_get_color_for_output (app->labeler, output, &output_color);
+ r = output_color.red / 65535.0;
+ g = output_color.green / 65535.0;
+ b = output_color.blue / 65535.0;
+
+ if (!output->on)
+ {
+ /* If the output is turned off, just darken the selected color */
+ r *= 0.2;
+ g *= 0.2;
+ b *= 0.2;
+ }
+
+ cairo_set_source_rgba (cr, r, g, b, 1.0);
+
+ foo_scroll_area_add_input_from_fill (FOO_SCROLL_AREA (app->area),
+ cr, on_output_event, output);
+ cairo_fill (cr);
+
+ if (output == app->current_output)
+ {
+ cairo_rectangle (cr, x + 2, y + 2, w * scale + 0.5 - 4, h * scale + 0.5 - 4);
+
+ cairo_set_line_width (cr, 4);
+ cairo_set_source_rgba (cr, 0.33, 0.43, 0.57, 1.0);
+ cairo_stroke (cr);
+ }
+
+ cairo_rectangle (cr, x + 0.5, y + 0.5, w * scale + 0.5 - 1, h * scale + 0.5 - 1);
+
+ cairo_set_line_width (cr, 1);
+ cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0);
+
+ cairo_stroke (cr);
+ cairo_set_line_width (cr, 2);
+
+ layout_set_font (layout, "Sans Bold 12");
+ pango_layout_get_pixel_extents (layout, &ink_extent, &log_extent);
+
+ available_w = w * scale + 0.5 - 6; /* Same as the inner rectangle's width, minus 1 pixel of padding on each side */
+ if (available_w < ink_extent.width)
+ factor = available_w / ink_extent.width;
+ else
+ factor = 1.0;
+
+ cairo_move_to (cr,
+ x + ((w * scale + 0.5) - factor * log_extent.width) / 2,
+ y + ((h * scale + 0.5) - factor * log_extent.height) / 2);
+
+ cairo_scale (cr, factor, factor);
+
+ if (output->on)
+ cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+ else
+ cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
+
+ pango_cairo_show_layout (cr, layout);
+
+ cairo_restore (cr);
+
+ g_object_unref (layout);
+}
+
+static void
+on_area_paint (FooScrollArea *area,
+ cairo_t *cr,
+ GdkRectangle *extent,
+ GdkRegion *region,
+ gpointer data)
+{
+ App *app = data;
+ double scale;
+ GList *connected_outputs = NULL;
+ GList *list;
+
+ paint_background (area, cr);
+
+ if (!app->current_configuration)
+ return;
+
+ scale = compute_scale (app);
+ connected_outputs = list_connected_outputs (app, NULL, NULL);
+
+#if 0
+ g_debug ("scale: %f", scale);
+#endif
+
+ for (list = connected_outputs; list != NULL; list = list->next)
+ {
+ paint_output (app, cr, g_list_position (connected_outputs, list));
+
+ if (app->current_configuration->clone)
+ break;
+ }
+}
+
+static void
+make_text_combo (GtkWidget *widget, int sort_column)
+{
+ GtkComboBox *box = GTK_COMBO_BOX (widget);
+ GtkListStore *store = gtk_list_store_new (
+ 6,
+ G_TYPE_STRING, /* Text */
+ G_TYPE_INT, /* Width */
+ G_TYPE_INT, /* Height */
+ G_TYPE_INT, /* Frequency */
+ G_TYPE_INT, /* Width * Height */
+ G_TYPE_INT); /* Rotation */
+
+ GtkCellRenderer *cell;
+
+ gtk_cell_layout_clear (GTK_CELL_LAYOUT (widget));
+
+ gtk_combo_box_set_model (box, GTK_TREE_MODEL (store));
+
+ cell = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (box), cell, TRUE);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (box), cell,
+ "text", 0,
+ NULL);
+
+ if (sort_column != -1)
+ {
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
+ sort_column,
+ GTK_SORT_DESCENDING);
+ }
+}
+
+static void
+compute_virtual_size_for_configuration (MateRRConfig *config, int *ret_width, int *ret_height)
+{
+ int i;
+ int width, height;
+
+ width = height = 0;
+
+ for (i = 0; config->outputs[i] != NULL; i++)
+ {
+ MateOutputInfo *output;
+
+ output = config->outputs[i];
+
+ if (output->on)
+ {
+ width = MAX (width, output->x + output->width);
+ height = MAX (height, output->y + output->height);
+ }
+ }
+
+ *ret_width = width;
+ *ret_height = height;
+}
+
+static void
+check_required_virtual_size (App *app)
+{
+ int req_width, req_height;
+ int min_width, max_width;
+ int min_height, max_height;
+
+ compute_virtual_size_for_configuration (app->current_configuration, &req_width, &req_height);
+
+ mate_rr_screen_get_ranges (app->screen, &min_width, &max_width, &min_height, &max_height);
+
+#if 0
+ g_debug ("X Server supports:");
+ g_debug ("min_width = %d, max_width = %d", min_width, max_width);
+ g_debug ("min_height = %d, max_height = %d", min_height, max_height);
+
+ g_debug ("Requesting size of %dx%d", req_width, req_height);
+#endif
+
+ if (!(min_width <= req_width && req_width <= max_width
+ && min_height <= req_height && req_height <= max_height))
+ {
+ /* FIXME: present a useful dialog, maybe even before the user tries to Apply */
+#if 0
+ g_debug ("Your X server needs a larger Virtual size!");
+#endif
+ }
+}
+
+static void
+begin_version2_apply_configuration (App *app, GdkWindow *parent_window, guint32 timestamp)
+{
+ XID parent_window_xid;
+
+ parent_window_xid = GDK_WINDOW_XID (parent_window);
+
+ app->proxy = dbus_g_proxy_new_for_name (app->connection,
+ "org.mate.SettingsDaemon",
+ "/org/mate/SettingsDaemon/XRANDR",
+ "org.mate.SettingsDaemon.XRANDR_2");
+ g_assert (app->proxy != NULL); /* that call does not fail unless we pass bogus names */
+
+ app->apply_configuration_state = APPLYING_VERSION_2;
+ app->proxy_call = dbus_g_proxy_begin_call (app->proxy, "ApplyConfiguration",
+ apply_configuration_returned_cb, app,
+ NULL,
+ G_TYPE_INT64, (gint64) parent_window_xid,
+ G_TYPE_INT64, (gint64) timestamp,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+ /* FIXME: we don't check for app->proxy_call == NULL, which could happen if
+ * the connection was disconnected. This is left as an exercise for the
+ * reader.
+ */
+}
+
+static void
+begin_version1_apply_configuration (App *app)
+{
+ app->proxy = dbus_g_proxy_new_for_name (app->connection,
+ "org.mate.SettingsDaemon",
+ "/org/mate/SettingsDaemon/XRANDR",
+ "org.mate.SettingsDaemon.XRANDR");
+ g_assert (app->proxy != NULL); /* that call does not fail unless we pass bogus names */
+
+ app->apply_configuration_state = APPLYING_VERSION_1;
+ app->proxy_call = dbus_g_proxy_begin_call (app->proxy, "ApplyConfiguration",
+ apply_configuration_returned_cb, app,
+ NULL,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+ /* FIXME: we don't check for app->proxy_call == NULL, which could happen if
+ * the connection was disconnected. This is left as an exercise for the
+ * reader.
+ */
+}
+
+static void
+ensure_current_configuration_is_saved (void)
+{
+ MateRRScreen *rr_screen;
+ MateRRConfig *rr_config;
+
+ /* Normally, mate_rr_config_save() creates a backup file based on the
+ * old monitors.xml. However, if *that* file didn't exist, there is
+ * nothing from which to create a backup. So, here we'll save the
+ * current/unchanged configuration and then let our caller call
+ * mate_rr_config_save() again with the new/changed configuration, so
+ * that there *will* be a backup file in the end.
+ */
+
+ rr_screen = mate_rr_screen_new (gdk_screen_get_default (), NULL, NULL, NULL); /* NULL-GError */
+ if (!rr_screen)
+ return;
+
+ rr_config = mate_rr_config_new_current (rr_screen);
+ mate_rr_config_save (rr_config, NULL); /* NULL-GError */
+
+ mate_rr_config_free (rr_config);
+ mate_rr_screen_destroy (rr_screen);
+}
+
+/* Callback for dbus_g_proxy_begin_call() */
+static void
+apply_configuration_returned_cb (DBusGProxy *proxy,
+ DBusGProxyCall *call_id,
+ void *data)
+{
+ App *app = data;
+ gboolean success;
+ GError *error;
+
+ g_assert (call_id == app->proxy_call);
+
+ error = NULL;
+ success = dbus_g_proxy_end_call (proxy, call_id, &error, G_TYPE_INVALID);
+
+ if (!success) {
+ if (app->apply_configuration_state == APPLYING_VERSION_2
+ && g_error_matches (error, DBUS_GERROR, DBUS_GERROR_UNKNOWN_METHOD)) {
+ g_error_free (error);
+
+ g_object_unref (app->proxy);
+ app->proxy = NULL;
+
+ begin_version1_apply_configuration (app);
+ return;
+ } else {
+ /* We don't pop up an error message; mate-settings-daemon already does that
+ * in case the selected RANDR configuration could not be applied.
+ */
+ g_error_free (error);
+ }
+ }
+
+ g_object_unref (app->proxy);
+ app->proxy = NULL;
+
+ dbus_g_connection_unref (app->connection);
+ app->connection = NULL;
+ app->proxy_call = NULL;
+
+ gtk_widget_set_sensitive (app->dialog, TRUE);
+}
+
+static gboolean
+sanitize_and_save_configuration (App *app)
+{
+ GError *error;
+
+ mate_rr_config_sanitize (app->current_configuration);
+
+ check_required_virtual_size (app);
+
+ foo_scroll_area_invalidate (FOO_SCROLL_AREA (app->area));
+
+ ensure_current_configuration_is_saved ();
+
+ error = NULL;
+ if (!mate_rr_config_save (app->current_configuration, &error))
+ {
+ error_message (app, _("Could not save the monitor configuration"), error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void
+apply (App *app)
+{
+ GError *error = NULL;
+
+ if (!sanitize_and_save_configuration (app))
+ return;
+
+ g_assert (app->connection == NULL);
+ g_assert (app->proxy == NULL);
+ g_assert (app->proxy_call == NULL);
+
+ app->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+ if (app->connection == NULL) {
+ error_message (app, _("Could not get session bus while applying display configuration"), error->message);
+ g_error_free (error);
+ return;
+ }
+
+ gtk_widget_set_sensitive (app->dialog, FALSE);
+
+ begin_version2_apply_configuration (app, gtk_widget_get_window (app->dialog), app->apply_button_clicked_timestamp);
+}
+
+#if 0
+/* Returns whether the graphics driver doesn't advertise RANDR 1.2 features, and just 1.0 */
+static gboolean
+driver_is_randr_10 (MateRRConfig *config)
+{
+ /* In the Xorg code, see xserver/randr/rrinfo.c:RRScanOldConfig(). It gets
+ * called when the graphics driver doesn't support RANDR 1.2 yet, just 1.0.
+ * In that case, the X server's base code (which supports RANDR 1.2) will
+ * simulate having a single output called "default". For drivers that *do*
+ * support RANDR 1.2, the separate outputs will be named differently, we
+ * hope.
+ *
+ * This heuristic is courtesy of Dirk Mueller <[email protected]>
+ *
+ * FIXME: however, we don't even check for XRRQueryVersion() returning 1.2, neither
+ * here nor in mate-desktop/libmatedesktop*.c. Do we need to check for that,
+ * or is mate_rr_screen_new()'s return value sufficient?
+ */
+
+ return (count_all_outputs (config) == 1 && strcmp (config->outputs[0]->name, "default") == 0);
+}
+#endif
+
+static void
+on_detect_displays (GtkWidget *widget, gpointer data)
+{
+ App *app = data;
+ GError *error;
+
+ error = NULL;
+ if (!mate_rr_screen_refresh (app->screen, &error)) {
+ if (error) {
+ error_message (app, _("Could not detect displays"), error->message);
+ g_error_free (error);
+ }
+ }
+}
+
+#define SHOW_ICON_KEY "/apps/mate_settings_daemon/xrandr/show_notification_icon"
+
+
+static void
+on_show_icon_toggled (GtkWidget *widget, gpointer data)
+{
+ GtkToggleButton *tb = GTK_TOGGLE_BUTTON (widget);
+ App *app = data;
+
+ mateconf_client_set_bool (app->client, SHOW_ICON_KEY,
+ gtk_toggle_button_get_active (tb), NULL);
+}
+
+static MateOutputInfo *
+get_nearest_output (MateRRConfig *configuration, int x, int y)
+{
+ int i;
+ int nearest_index;
+ int nearest_dist;
+
+ nearest_index = -1;
+ nearest_dist = G_MAXINT;
+
+ for (i = 0; configuration->outputs[i] != NULL; i++)
+ {
+ MateOutputInfo *output;
+ int dist_x, dist_y;
+
+ output = configuration->outputs[i];
+
+ if (!(output->connected && output->on))
+ continue;
+
+ if (x < output->x)
+ dist_x = output->x - x;
+ else if (x >= output->x + output->width)
+ dist_x = x - (output->x + output->width) + 1;
+ else
+ dist_x = 0;
+
+ if (y < output->y)
+ dist_y = output->y - y;
+ else if (y >= output->y + output->height)
+ dist_y = y - (output->y + output->height) + 1;
+ else
+ dist_y = 0;
+
+ if (MIN (dist_x, dist_y) < nearest_dist)
+ {
+ nearest_dist = MIN (dist_x, dist_y);
+ nearest_index = i;
+ }
+ }
+
+ if (nearest_index != -1)
+ return configuration->outputs[nearest_index];
+ else
+ return NULL;
+
+}
+
+/* Gets the output that contains the largest intersection with the window.
+ * Logic stolen from gdk_screen_get_monitor_at_window().
+ */
+static MateOutputInfo *
+get_output_for_window (MateRRConfig *configuration, GdkWindow *window)
+{
+ GdkRectangle win_rect;
+ int i;
+ int largest_area;
+ int largest_index;
+
+ gdk_window_get_geometry (window, &win_rect.x, &win_rect.y, &win_rect.width, &win_rect.height, NULL);
+ gdk_window_get_origin (window, &win_rect.x, &win_rect.y);
+
+ largest_area = 0;
+ largest_index = -1;
+
+ for (i = 0; configuration->outputs[i] != NULL; i++)
+ {
+ MateOutputInfo *output;
+ GdkRectangle output_rect, intersection;
+
+ output = configuration->outputs[i];
+
+ output_rect.x = output->x;
+ output_rect.y = output->y;
+ output_rect.width = output->width;
+ output_rect.height = output->height;
+
+ if (output->connected && gdk_rectangle_intersect (&win_rect, &output_rect, &intersection))
+ {
+ int area;
+
+ area = intersection.width * intersection.height;
+ if (area > largest_area)
+ {
+ largest_area = area;
+ largest_index = i;
+ }
+ }
+ }
+
+ if (largest_index != -1)
+ return configuration->outputs[largest_index];
+ else
+ return get_nearest_output (configuration,
+ win_rect.x + win_rect.width / 2,
+ win_rect.y + win_rect.height / 2);
+}
+
+/* We select the current output, i.e. select the one being edited, based on
+ * which output is showing the configuration dialog.
+ */
+static void
+select_current_output_from_dialog_position (App *app)
+{
+ if (gtk_widget_get_realized (app->dialog))
+ app->current_output = get_output_for_window (app->current_configuration, gtk_widget_get_window (app->dialog));
+ else
+ app->current_output = NULL;
+
+ rebuild_gui (app);
+}
+
+/* This is a GtkWidget::map-event handler. We wait for the display-properties
+ * dialog to be mapped, and then we select the output which corresponds to the
+ * monitor on which the dialog is being shown.
+ */
+static gboolean
+dialog_map_event_cb (GtkWidget *widget, GdkEventAny *event, gpointer data)
+{
+ App *app = data;
+
+ select_current_output_from_dialog_position (app);
+ return FALSE;
+}
+
+static void
+hide_help_button (App *app)
+{
+ GtkWidget *action_area;
+ GList *children;
+ GList *l;
+
+ action_area = gtk_dialog_get_action_area (GTK_DIALOG (app->dialog));
+ children = gtk_container_get_children (GTK_CONTAINER (action_area));
+
+ for (l = children; l; l = l->next)
+ {
+ GtkWidget *child;
+ int response;
+
+ child = GTK_WIDGET (l->data);
+
+ response = gtk_dialog_get_response_for_widget (GTK_DIALOG (app->dialog), child);
+ if (response == GTK_RESPONSE_HELP)
+ {
+ gtk_widget_hide (child);
+ return;
+ }
+ }
+}
+
+static void
+apply_button_clicked_cb (GtkButton *button, gpointer data)
+{
+ App *app = data;
+
+ /* We simply store the timestamp at which the Apply button was clicked.
+ * We'll just wait for the dialog to return from gtk_dialog_run(), and
+ * *then* use the timestamp when applying the RANDR configuration.
+ */
+
+ app->apply_button_clicked_timestamp = gtk_get_current_event_time ();
+}
+
+static void
+success_dialog_for_make_default (App *app)
+{
+ GtkWidget *dialog;
+
+ dialog = gtk_message_dialog_new (GTK_WINDOW (app->dialog),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_OK,
+ _("The monitor configuration has been saved"));
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ _("This configuration will be used the next time someone logs in."));
+
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+}
+
+static void
+error_dialog_for_make_default (App *app, const char *error_text)
+{
+ error_message (app, _("Could not set the default configuration for monitors"), error_text);
+}
+
+static void
+make_default (App *app)
+{
+ char *command_line;
+ char *source_filename;
+ char *dest_filename;
+ char *dest_basename;
+ char *std_error;
+ gint exit_status;
+ GError *error;
+
+ if (!sanitize_and_save_configuration (app))
+ return;
+
+ dest_filename = mateconf_client_get_string (app->client, "/apps/mate_settings_daemon/xrandr/default_configuration_file", NULL);
+ if (!dest_filename)
+ return; /* FIXME: present an error? */
+
+ dest_basename = g_path_get_basename (dest_filename);
+
+ source_filename = mate_rr_config_get_intended_filename ();
+
+ command_line = g_strdup_printf ("pkexec %s/mate-display-properties-install-systemwide %s %s",
+ SBINDIR,
+ source_filename,
+ dest_basename);
+
+ error = NULL;
+ if (!g_spawn_command_line_sync (command_line, NULL, &std_error, &exit_status, &error))
+ {
+ error_dialog_for_make_default (app, error->message);
+ g_error_free (error);
+ }
+ else if (!WIFEXITED (exit_status) || WEXITSTATUS (exit_status) != 0)
+ {
+ error_dialog_for_make_default (app, std_error);
+ }
+ else
+ {
+ success_dialog_for_make_default (app);
+ }
+
+ g_free (std_error);
+ g_free (dest_filename);
+ g_free (dest_basename);
+ g_free (source_filename);
+ g_free (command_line);
+}
+
+static GtkWidget*
+_gtk_builder_get_widget (GtkBuilder *builder, const gchar *name)
+{
+ return GTK_WIDGET (gtk_builder_get_object (builder, name));
+}
+
+static void
+run_application (App *app)
+{
+#ifndef UIDIR
+#define UIDIR "."
+#endif
+#define UI_FILE UIDIR "/display-capplet.ui"
+ GtkBuilder *builder;
+ GtkWidget *align;
+ GError *error;
+
+ error = NULL;
+ builder = gtk_builder_new ();
+
+ if (gtk_builder_add_from_file (builder, UI_FILE, &error) == 0)
+ {
+ g_warning ("Could not parse UI definition: %s", error->message);
+ g_error_free (error);
+ g_object_unref (builder);
+ return;
+ }
+
+ app->screen = mate_rr_screen_new (gdk_screen_get_default (),
+ on_screen_changed, app, &error);
+ if (!app->screen)
+ {
+ error_message (NULL, _("Could not get screen information"), error->message);
+ g_error_free (error);
+ g_object_unref (builder);
+ return;
+ }
+
+ app->client = mateconf_client_get_default ();
+
+ app->dialog = _gtk_builder_get_widget (builder, "dialog");
+ g_signal_connect_after (app->dialog, "map-event",
+ G_CALLBACK (dialog_map_event_cb), app);
+
+ gtk_window_set_default_icon_name ("mate-preferences-desktop-display");
+ gtk_window_set_icon_name (GTK_WINDOW (app->dialog),
+ "mate-preferences-desktop-display");
+
+ app->current_monitor_event_box = _gtk_builder_get_widget (builder,
+ "current_monitor_event_box");
+ app->current_monitor_label = _gtk_builder_get_widget (builder,
+ "current_monitor_label");
+
+ app->monitor_on_radio = _gtk_builder_get_widget (builder,
+ "monitor_on_radio");
+ app->monitor_off_radio = _gtk_builder_get_widget (builder,
+ "monitor_off_radio");
+ g_signal_connect (app->monitor_on_radio, "toggled",
+ G_CALLBACK (monitor_on_off_toggled_cb), app);
+ g_signal_connect (app->monitor_off_radio, "toggled",
+ G_CALLBACK (monitor_on_off_toggled_cb), app);
+
+ app->resolution_combo = _gtk_builder_get_widget (builder,
+ "resolution_combo");
+ g_signal_connect (app->resolution_combo, "changed",
+ G_CALLBACK (on_resolution_changed), app);
+
+ app->refresh_combo = _gtk_builder_get_widget (builder, "refresh_combo");
+ g_signal_connect (app->refresh_combo, "changed",
+ G_CALLBACK (on_rate_changed), app);
+
+ app->rotation_combo = _gtk_builder_get_widget (builder, "rotation_combo");
+ g_signal_connect (app->rotation_combo, "changed",
+ G_CALLBACK (on_rotation_changed), app);
+
+ app->clone_checkbox = _gtk_builder_get_widget (builder, "clone_checkbox");
+ g_signal_connect (app->clone_checkbox, "toggled",
+ G_CALLBACK (on_clone_changed), app);
+
+ g_signal_connect (_gtk_builder_get_widget (builder, "detect_displays_button"),
+ "clicked", G_CALLBACK (on_detect_displays), app);
+
+ app->show_icon_checkbox = _gtk_builder_get_widget (builder,
+ "show_notification_icon");
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->show_icon_checkbox),
+ mateconf_client_get_bool (app->client, SHOW_ICON_KEY, NULL));
+
+ g_signal_connect (app->show_icon_checkbox, "toggled", G_CALLBACK (on_show_icon_toggled), app);
+
+ app->panel_checkbox = _gtk_builder_get_widget (builder, "panel_checkbox");
+
+ make_text_combo (app->resolution_combo, 4);
+ make_text_combo (app->refresh_combo, 3);
+ make_text_combo (app->rotation_combo, -1);
+
+ g_assert (app->panel_checkbox);
+
+ /* Scroll Area */
+ app->area = (GtkWidget *)foo_scroll_area_new ();
+
+ g_object_set_data (G_OBJECT (app->area), "app", app);
+
+ set_monitors_tooltip (app, FALSE);
+
+ /* FIXME: this should be computed dynamically */
+ foo_scroll_area_set_min_size (FOO_SCROLL_AREA (app->area), -1, 200);
+ gtk_widget_show (app->area);
+ g_signal_connect (app->area, "paint",
+ G_CALLBACK (on_area_paint), app);
+ g_signal_connect (app->area, "viewport_changed",
+ G_CALLBACK (on_viewport_changed), app);
+
+ align = _gtk_builder_get_widget (builder, "align");
+
+ gtk_container_add (GTK_CONTAINER (align), app->area);
+
+ /* Until we have help to show, we'll just hide the Help button */
+ hide_help_button (app);
+
+ app->apply_button = _gtk_builder_get_widget (builder, "apply_button");
+ g_signal_connect (app->apply_button, "clicked",
+ G_CALLBACK (apply_button_clicked_cb), app);
+
+ on_screen_changed (app->screen, app);
+
+ g_object_unref (builder);
+
+restart:
+ switch (gtk_dialog_run (GTK_DIALOG (app->dialog)))
+ {
+ default:
+ /* Fall Through */
+ case GTK_RESPONSE_DELETE_EVENT:
+ case GTK_RESPONSE_CLOSE:
+#if 0
+ g_debug ("Close");
+#endif
+ break;
+
+ case GTK_RESPONSE_HELP:
+#if 0
+ g_debug ("Help");
+#endif
+ goto restart;
+ break;
+
+ case GTK_RESPONSE_APPLY:
+ apply (app);
+ goto restart;
+ break;
+
+ case RESPONSE_MAKE_DEFAULT:
+ make_default (app);
+ goto restart;
+ break;
+ }
+
+ gtk_widget_destroy (app->dialog);
+ mate_rr_screen_destroy (app->screen);
+ g_object_unref (app->client);
+}
+
+int
+main (int argc, char **argv)
+{
+ App *app;
+
+ bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ textdomain (GETTEXT_PACKAGE);
+
+ gtk_init (&argc, &argv);
+
+ app = g_new0 (App, 1);
+
+ run_application (app);
+
+ g_free (app);
+
+ return 0;
+}