gsd-device-mapper does not apply mapping when monitor setup is changed
Submitted by Matthijs Kooijman
Created attachment 287110 Proof of concept fix
I have a laptop with an external monitor connected. My wacom tablet is set up to be mapped to the external monitor. This works fine when first configure this, or when I plug my tablet in and out, but when I close and reopen my laptop lid, it does not reapply the correct mapping (stretching my tablet over both screens).
Looking at the source code, I found that the actual mapping of outputs happens in settings_get_display, which is only called from device_settings_changed_cb and input_info_new. When the display configuration changes, screen_changed_cb is called, which calls _device_mapper_update_outputs which calls mapper_recalculate_candidates, which only does stuff with guessing candidates for integrated screens and systems, but it does not actually look at the configured output for a device.
What is slightly weird is that the info->output variable somehow gets unset. I've mapped the tablet to my external monitor and then close the laptop screen, so the external monitor should always stay available and there is no reason for info->output to get unset. However, perhaps gnome_rr_screen_list_outputs returns a different value for the same screen after the change? In any case, this isn't really important - if I would map the tablet to the laptop screen, close it and reopen it, it should also still work, but I expect it doesn't with the current code.
I've attached a patch that fixes this problem, though it's probably not the best way to fix it. Right now, this lets mapper_recalculate_candidates also look at the configured display, but that doesn't reallly fit within the functions scope (looking at the name). Also, this duplicates some code from device_settings_changed_cb / input_info_new which might be better to factor out in a separate function. Since I'm not familiar with the code so much, I'm not sure what the best approach would be.
I also attached some output from gsd --debug with and without this patch applied to illustrate the problem. I'm happy to do more testing of any patches or provide more info if needed.
All this is tested on gnome 3.12, since I haven't set a complete gnome compilation environment up here (compiling gsd through a patched Debian package and pbuilder). However, looking at the commit log, I don't think any related changes have been made to gsd since 3.12.
Patch 287110, "Proof of concept fix":