105 lines
2.7 KiB
Vala
105 lines
2.7 KiB
Vala
/*
|
|
* pdf-presenter - advanced pdf presentation util
|
|
*
|
|
* Copyright (C) 2009 Sebastian Reichel <sre@ring0.de>
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
* THE SOFTWARE.
|
|
*/
|
|
|
|
class Monitor {
|
|
Gdk.Screen screen;
|
|
string[] monitors;
|
|
|
|
signal void connected(string name);
|
|
signal void disconnected(string name);
|
|
|
|
public Monitor(Gdk.Screen scr) {
|
|
screen = scr;
|
|
monitors = get_list();
|
|
screen.monitors_changed.connect(on_monitor_changed);
|
|
}
|
|
|
|
private string[] get_list() {
|
|
string[] output = {};
|
|
for(int i=0; i<screen.get_n_monitors(); i++)
|
|
output += screen.get_monitor_plug_name(i);
|
|
return output;
|
|
}
|
|
|
|
public string[] get_all() {
|
|
return monitors;
|
|
}
|
|
|
|
public void get_size(string monitor, out int x, out int y, out int w, out int h) {
|
|
for(int i=0; i<screen.get_n_monitors(); i++) {
|
|
Gdk.Rectangle rect;
|
|
screen.get_monitor_geometry(i, out rect);
|
|
|
|
if(screen.get_monitor_plug_name(i) == monitor) {
|
|
x = rect.x;
|
|
y = rect.y;
|
|
w = rect.width;
|
|
h = rect.height;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
void on_monitor_changed() {
|
|
string[] new_monitors;
|
|
|
|
new_monitors = get_list();
|
|
|
|
if(monitors.length == new_monitors.length)
|
|
return;
|
|
|
|
if(monitors.length < new_monitors.length) {
|
|
foreach(string a in new_monitors) {
|
|
bool found=false;
|
|
foreach(string b in monitors) {
|
|
if(a == b) {
|
|
found=true;
|
|
break;
|
|
}
|
|
}
|
|
if(!found) {
|
|
monitors = new_monitors;
|
|
connected(a);
|
|
return;
|
|
}
|
|
}
|
|
} else {
|
|
foreach(string a in monitors) {
|
|
bool found=false;
|
|
foreach(string b in new_monitors) {
|
|
if(a == b) {
|
|
found=true;
|
|
break;
|
|
}
|
|
}
|
|
if(!found) {
|
|
monitors = new_monitors;
|
|
disconnected(a);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|