1145
1145
window.SetDefaultSize (data.Data.Width,
1146
1146
data.Data.Height);
1148
if (data.Data.HasPosition ())
1148
if (data.Data.HasPosition ()) {
1149
// This would return the monitor where the point is, or the nearest one,
1150
// protecting us from restoring onto non-existing monitor
1151
int mon = window.Screen.GetMonitorAtPoint(data.Data.X, data.Data.Y);
1152
Gdk.Rectangle mon_geom = window.Screen.GetMonitorGeometry(mon);
1153
if (!mon_geom.Contains(data.Data.X, data.Data.Y)) {
1154
// If we're here, then the saved position was
1155
// on some now-disconnected monitor
1156
Logger.Debug("Saved note position {0} x {1} is off-screen, " +
1157
"we'll move it to the center of the nearest monitor",
1158
data.Data.X, data.Data.Y);
1159
data.Data.X = mon_geom.Right / 2 - data.Data.Width / 2;
1160
data.Data.Y = mon_geom.Bottom / 2 - data.Data.Height / 2;
1163
// 100px is a clearance space to accommodate taskbars and such.
1164
// There's no nice and cross-platform way to get this information, but
1165
// System.Windows.Forms.Screen.GetWorkingArea which adds unwanted deps
1166
int clearance = 100;
1167
int ne_x = data.Data.X + data.Data.Width + clearance;
1168
if (ne_x > mon_geom.Right) {
1169
Logger.Debug("Note runs beyond the screen on X coord, " +
1170
"we'll adjust the position");
1171
// We'll first try to just move the window so that it's shown in full
1172
int new_x = data.Data.X - (ne_x - mon_geom.Right);
1173
if (new_x >= mon_geom.Left+clearance) {
1174
// New position places the whole note within the screen
1175
data.Data.X = new_x;
1176
Logger.Debug("Moving note to {0} on X axis", new_x);
1178
// Adjusted position is still beyond the allowable area,
1179
// so we'll adjust & resize the note window
1180
data.Data.X = mon_geom.Left + clearance;
1181
data.Data.Width = mon_geom.Width - 2*clearance;
1183
window.GetSize(out win_w, out win_h);
1184
window.Resize(data.Data.Width, win_h);
1185
Logger.Debug("Note is too wide to fully fit, " +
1186
"can't move nicely, " +
1187
"moving to fallback position {0} and resizing to {1} on X axis",
1188
data.Data.X, data.Data.Width);
1192
int sw_y = data.Data.Y + data.Data.Height + clearance;
1193
if (sw_y > mon_geom.Bottom) {
1194
Logger.Debug("Note runs beyond the screen on Y coord, " +
1195
"we'll adjust the position");
1196
// We'll first try to just move the window so that it's shown in full
1197
int new_y = data.Data.Y - (sw_y - mon_geom.Bottom);
1198
if (new_y >= mon_geom.Top+clearance) {
1199
data.Data.Y = new_y;
1200
Logger.Debug("Moving note to {0} on Y axis", new_y);
1202
// Adjusted position is still beyond the allowable area,
1203
// so we'll adjust & resize the note window
1204
data.Data.Y = mon_geom.Top + clearance;
1205
data.Data.Height = mon_geom.Height - 2*clearance;
1207
window.GetSize(out win_w, out win_h);
1208
window.Resize(win_w, data.Data.Height);
1209
Logger.Debug("Note is too tall to fully fit, " +
1210
"can't move nicely, " +
1211
"moving to fallback position {0} and resizing to {1} on Y axis",
1212
data.Data.Y, data.Data.Height);
1215
// Now we're sure this positions the note within the screen
1149
1216
window.Move (data.Data.X, data.Data.Y);
1151
1219
// This is here because emiting inside
1152
1220
// OnRealized causes segfaults.