File size: 25,622 Bytes
048541b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
###################################################
#
#  Copyright (C) 2008-2013 Mario Kemper <mario.kemper@gmail.com>
#
#  This file is part of Shutter.
#
#  Shutter 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 3 of the License, or
#  (at your option) any later version.
#
#  Shutter 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 Shutter; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
#
###################################################

package Shutter::App::ContextMenus;

#Builders for Shutter's context/popup menus (workspace, window list,
#tray icon, "open with" programs, web timeout and quick profile select).
#
#These used to be fct_ret_*_menu subs in bin/shutter. bin/shutter keeps
#thin wrappers with the original names that pass the former file-scoped
#globals explicitly. Globals that the menus assign to (directly or from a
#callback) are passed as scalar references. Callbacks still dispatch to
#evt_*/fct_* subs that live in package Shutter::App.

#modules
#--------------------------------------
use utf8;
use strict;
use warnings;
use Gtk3;
use Encode;

#Glib
use Glib qw/TRUE FALSE/;

#--------------------------------------

sub workspace_menu {
	my ($sc, $d, $settings_xml, $x11_supported, $current_monitor_active_ref, $init) = @_;

	my $menu_wrksp = Gtk3::Menu->new;
	unless ($x11_supported) {

		#On Wayland we can't enumerate workspaces via libwnck, but we can still
		#offer to capture a single monitor by cropping the portal screenshot.
		my $gdk_screen = Gtk3::Gdk::Screen::get_default;
		my $n_mons     = $gdk_screen->get_n_monitors;
		if ($n_mons > 1) {
			for (my $i = 0 ; $i < $n_mons ; $i++) {
				my $geo  = $gdk_screen->get_monitor_geometry($i);
				my $plug = eval { $gdk_screen->get_monitor_plug_name($i) };
				my $label =
					$plug
					? sprintf("%s (%dx%d)",                  $plug,  $geo->{width}, $geo->{height})
					: sprintf($d->get("Monitor %d (%dx%d)"), $i + 1, $geo->{width}, $geo->{height});
				my $mon_item = Gtk3::MenuItem->new_with_label($label);
				$mon_item->signal_connect('activate' => \&Shutter::App::evt_take_screenshot, "shutter_monitor_direct$i");
				$menu_wrksp->append($mon_item);
			}
			$menu_wrksp->show_all;
		}
		return $menu_wrksp;
	}

	my $wnck_screen = Wnck::Screen::get_default();
	unless ($wnck_screen) {
		${$current_monitor_active_ref} = Gtk3::CheckMenuItem->new_with_label($d->get("Limit to current monitor"));
		return $menu_wrksp;
	}
	$wnck_screen->force_update();

	#we determine the wm name but on older
	#version of libwnck (or the bindings)
	#the needed method is not available
	#in this case we use gdk to do it
	#
	#this leads to a known problem when switching
	#the wm => wm_name will still remain the old one
	#but it doesn't work on gtk3
	my $wm_name;
	if ($wnck_screen->can('get_window_manager_name')) {
		$wm_name = $wnck_screen->get_window_manager_name;
	}

	my $active_workspace = $wnck_screen->get_active_workspace;

	#we need to handle different window managers here because there are some different models related
	#to workspaces and viewports
	#	compiz uses "multiple workspaces" - "multiple viewports" model for example
	#	default gnome wm metacity simply uses multiple workspaces
	#we will try to handle them by name
	my @workspaces = ();
	for (my $wcount = 0 ; $wcount < $wnck_screen->get_workspace_count ; $wcount++) {
		push(@workspaces, $wnck_screen->get_workspace($wcount));
	}

	foreach my $space (@workspaces) {
		next unless defined $space;

		#compiz
		print "Current window manager: ", $wm_name, "\n" if $sc->get_debug;
		if ($wm_name =~ /compiz/i) {

			#calculate viewports with size of workspace
			my $vpx = $space->get_viewport_x;
			my $vpy = $space->get_viewport_y;

			my $n_viewports_column = int($space->get_width / $wnck_screen->get_width);
			my $n_viewports_rows   = int($space->get_height / $wnck_screen->get_height);

			#rows
			for (my $j = 0 ; $j < $n_viewports_rows ; $j++) {

				#columns
				for (my $i = 0 ; $i < $n_viewports_column ; $i++) {
					my @vp      = ($i * $wnck_screen->get_width, $j * $wnck_screen->get_height);
					my $vp_name = "$wm_name x: $i y: $j";

					print "shutter_wrksp_direct_compiz" . $vp[0] . "x" . $vp[1] . "\n"
						if $sc->get_debug;

					my $vp_item = Gtk3::MenuItem->new_with_label(ucfirst $vp_name);
					$vp_item->signal_connect(
						'activate' => \&Shutter::App::evt_take_screenshot,
						"shutter_wrksp_direct_compiz" . $vp[0] . "x" . $vp[1]);
					$menu_wrksp->append($vp_item);

					#do not offer current viewport
					if ($vp[0] == $vpx && $vp[1] == $vpy) {
						$vp_item->set_sensitive(FALSE);
					}
				}    #columns
			}    #rows

			#all other wm manager like metacity etc.
			#we could add more of them here if needed
		} else {

			my $wrkspace_item = Gtk3::MenuItem->new_with_label($space->get_name);
			$wrkspace_item->signal_connect(
				'activate' => \&Shutter::App::evt_take_screenshot,
				"shutter_wrksp_direct" . $space->get_number
			);
			$menu_wrksp->append($wrkspace_item);

			if (   $active_workspace
				&& $active_workspace->get_number == $space->get_number)
			{
				$wrkspace_item->set_sensitive(FALSE);
			}

		}
	}

	#entry for capturing all workspaces
	$menu_wrksp->append(Gtk3::SeparatorMenuItem->new);

	my $allwspaces_item = Gtk3::MenuItem->new_with_label($d->get("Capture All Workspaces"));
	$allwspaces_item->signal_connect(
		'activate' => \&Shutter::App::evt_take_screenshot,
		"shutter_wrksp_direct" . 'all'
	);
	$menu_wrksp->append($allwspaces_item);

	#monitor flag
	my $n_mons = Gtk3::Gdk::Screen::get_default->get_n_monitors;

	#use only current monitor
	$menu_wrksp->append(Gtk3::SeparatorMenuItem->new);
	if ($init) {
		${$current_monitor_active_ref} = Gtk3::CheckMenuItem->new_with_label($d->get("Limit to current monitor"));
		if (defined $settings_xml->{'general'}->{'current_monitor_active'}) {
			${$current_monitor_active_ref}->set_active($settings_xml->{'general'}->{'current_monitor_active'});
		} else {
			${$current_monitor_active_ref}->set_active(FALSE);
		}
		$menu_wrksp->append(${$current_monitor_active_ref});
	} else {
		${$current_monitor_active_ref}->reparent($menu_wrksp);
	}

	${$current_monitor_active_ref}->set_tooltip_text(
		sprintf(
			$d->nget(
				"This option is only useful when you are running a multi-monitor system (%d monitor detected).\nEnable it to capture only the current monitor.",
				"This option is only useful when you are running a multi-monitor system (%d monitors detected).\nEnable it to capture only the current monitor.",
				$n_mons
			),
			$n_mons
		));
	if ($n_mons > 1) {
		${$current_monitor_active_ref}->set_sensitive(TRUE);
	} else {
		${$current_monitor_active_ref}->set_active(FALSE);
		${$current_monitor_active_ref}->set_sensitive(FALSE);
	}

	$menu_wrksp->show_all();
	return $menu_wrksp;
}

sub window_menu {
	my ($sc, $d, $lp, $shf, $shutter_root, $wnck_screen) = @_;

	my $menu_windows = Gtk3::Menu->new;
	return $menu_windows unless $wnck_screen;

	my $active_workspace = $wnck_screen->get_active_workspace;
	my $icontheme        = $sc->get_theme;

	#add item for active window
	my $active_window_item_image;
	if ($icontheme->has_icon('preferences-system-windows')) {
		$active_window_item_image = Gtk3::Image->new_from_icon_name('preferences-system-windows', 'menu');
	} else {
		$active_window_item_image = Gtk3::Image->new_from_pixbuf($lp->load("$shutter_root/share/shutter/resources/icons/sel_window_active.svg", $shf->icon_size('menu')));
	}

	my $active_window_item = Gtk3::ImageMenuItem->new_with_label($d->get("Active Window"));
	$active_window_item->set_image($active_window_item_image);
	$active_window_item->set('always_show_image' => TRUE);

	$active_window_item->set_tooltip_text($d->get("Capture the last active window"));

	$active_window_item->signal_connect(
		'activate' => \&Shutter::App::evt_take_screenshot,
		'awindow'
	);

	$menu_windows->append($active_window_item);
	$menu_windows->append(Gtk3::SeparatorMenuItem->new);

	# Check if we can retrieve the list of stacked windows first, otherwise we will run into a crash, see issue 659

	unless ($wnck_screen->get_windows_stacked) {
		print "ERROR: The window list could not be retrieved and has been disabled, see https://github.com/shutter-project/shutter/issues/659";
		return $menu_windows;
	}

	#add all windows to menu to capture it directly

	foreach my $win (@{$wnck_screen->get_windows_stacked}) {
		if ($active_workspace && $win->is_on_workspace($active_workspace)) {
			my $win_name = $win->get_name;
			Encode::_utf8_on($win_name);
			my $window_item = Gtk3::ImageMenuItem->new_with_label($win_name);
			foreach my $child ($window_item->get_children) {
				if ($child =~ /Gtk3::AccelLabel/) {
					$child->set_width_chars(50);
					$child->set_ellipsize('middle');
					last;
				}
			}
			$window_item->set_image(Gtk3::Image->new_from_pixbuf($win->get_mini_icon));
			$window_item->set('always_show_image' => TRUE);
			$window_item->signal_connect(
				'activate' => \&Shutter::App::evt_take_screenshot,
				"shutter_window_direct" . $win->get_xid
			);
			$menu_windows->append($window_item);
		}
	}

	$menu_windows->show_all;
	return $menu_windows;
}

sub tray_menu {
	my ($sc, $d, $lp, $shf, $shutter_root, $x11_supported, $gnome_web_photo, $is_hidden_ref) = @_;

	my $traytheme = $sc->get_theme;

	my $menu_tray = Gtk3::Menu->new();

	#selection
	my $menuitem_select = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('_Selection'));

	# served via interactive XDG portal on Wayland too
	$menuitem_select->set_sensitive(TRUE);
	eval {
		my $ccursor_pb = Gtk3::Gdk::Cursor::new('left_ptr')->get_image->scale_simple($shf->icon_size('menu'), 'bilinear');
		$menuitem_select->set_image(Gtk3::Image->new_from_pixbuf($ccursor_pb));
	};
	if ($@) {
		if ($traytheme->has_icon('applications-accessories')) {
			$menuitem_select->set_image(Gtk3::Image->new_from_icon_name('applications-accessories', 'menu'));
		} else {
			$menuitem_select->set_image(Gtk3::Image->new_from_pixbuf($lp->load("$shutter_root/share/shutter/resources/icons/selection.svg", $shf->icon_size('menu'))));
		}
	}
	$menuitem_select->signal_connect(
		activate => \&Shutter::App::evt_take_screenshot,
		'tray_select'
	);

	#full screen
	my $menuitem_full = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('_Desktop'));
	if ($traytheme->has_icon('user-desktop')) {
		$menuitem_full->set_image(Gtk3::Image->new_from_icon_name('user-desktop', 'menu'));
	} elsif ($traytheme->has_icon('desktop')) {
		$menuitem_full->set_image(Gtk3::Image->new_from_icon_name('desktop', 'menu'));
	} else {
		$menuitem_full->set_image(Gtk3::Image->new_from_pixbuf($lp->load("$shutter_root/share/shutter/resources/icons/desktop.svg", $shf->icon_size('menu'))));
	}
	$menuitem_full->signal_connect(
		activate => \&Shutter::App::evt_take_screenshot,
		'tray_full'
	);

	#~ #awindow
	#~ my $menuitem_awindow = Gtk3::ImageMenuItem->new_with_mnemonic( $d->get('_Active Window') );
	#~ if($traytheme->has_icon('preferences-system-windows')){
	#~ $menuitem_awindow->set_image( Gtk3::Image->new_from_icon_name( 'preferences-system-windows', 'menu' ) );
	#~ }else{
	#~ $menuitem_awindow->set_image(
	#~ Gtk3::Image->new_from_pixbuf(
	#~ $lp->load( "$shutter_root/share/shutter/resources/icons/sel_window_active.svg", $shf->icon_size('menu') )
	#~ )
	#~ );
	#~ }
	#~ $menuitem_awindow->signal_connect(
	#~ activate => \&Shutter::App::evt_take_screenshot,
	#~ 'tray_awindow'
	#~ );

	#window
	my $menuitem_window = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('Window _under Cursor'));

	# served via interactive XDG portal on Wayland too
	$menuitem_window->set_sensitive(TRUE);
	if ($traytheme->has_icon('preferences-system-windows')) {
		$menuitem_window->set_image(Gtk3::Image->new_from_icon_name('preferences-system-windows', 'menu'));
	} else {
		$menuitem_window->set_image(Gtk3::Image->new_from_pixbuf($lp->load("$shutter_root/share/shutter/resources/icons/sel_window.svg", $shf->icon_size('menu'))));
	}
	$menuitem_window->signal_connect(
		activate => \&Shutter::App::evt_take_screenshot,
		'tray_window'
	);

	#window list
	my $menuitem_window_list = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('Select W_indow'));
	$menuitem_window_list->set_sensitive($x11_supported);
	if ($traytheme->has_icon('preferences-system-windows')) {
		$menuitem_window_list->set_image(Gtk3::Image->new_from_icon_name('preferences-system-windows', 'menu'));
	} else {
		$menuitem_window_list->set_image(Gtk3::Image->new_from_pixbuf($lp->load("$shutter_root/share/shutter/resources/icons/sel_window.svg", $shf->icon_size('menu'))));
	}
	$menuitem_window_list->set_name('windowlist');
	$menuitem_window_list->set_submenu(Shutter::App::fct_ret_window_menu());

	#section
	# No sections for now: https://github.com/shutter-project/shutter/issues/25
	#my $menuitem_window_sect = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('Se_ction'));
	#if ($traytheme->has_icon('gdm-xnest')) {
	#	$menuitem_window_sect->set_image(Gtk3::Image->new_from_icon_name('gdm-xnest', 'menu'));
	#} else {
	#	$menuitem_window_sect->set_image(Gtk3::Image->new_from_pixbuf($lp->load("$shutter_root/share/shutter/resources/icons/sel_window_section.svg", $shf->icon_size('menu'))));
	#}
	#$menuitem_window_sect->signal_connect(
	#	activate => \&Shutter::App::evt_take_screenshot,
	#	'tray_section'
	#);

	#menu
	my $menuitem_window_menu = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('_Menu'));
	$menuitem_window_menu->set_sensitive($x11_supported);
	if ($traytheme->has_icon('alacarte')) {
		$menuitem_window_menu->set_image(Gtk3::Image->new_from_icon_name('alacarte', 'menu'));
	} else {
		$menuitem_window_menu->set_image(Gtk3::Image->new_from_pixbuf($lp->load("$shutter_root/share/shutter/resources/icons/sel_window_menu.svg", $shf->icon_size('menu'))));
	}
	$menuitem_window_menu->signal_connect(
		activate => \&Shutter::App::evt_take_screenshot,
		'tray_menu'
	);

	#tooltip
	my $menuitem_window_tooltip = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('_Tooltip'));
	$menuitem_window_tooltip->set_sensitive($x11_supported);
	if ($traytheme->has_icon('help-faq')) {
		$menuitem_window_tooltip->set_image(Gtk3::Image->new_from_icon_name('help-faq', 'menu'));
	} else {
		$menuitem_window_tooltip->set_image(Gtk3::Image->new_from_pixbuf($lp->load("$shutter_root/share/shutter/resources/icons/sel_window_tooltip.svg", $shf->icon_size('menu'))));
	}
	$menuitem_window_tooltip->signal_connect(
		activate => \&Shutter::App::evt_take_screenshot,
		'tray_tooltip'
	);

	#web
	my $menuitem_web = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('_Web'));
	$menuitem_web->set_sensitive($gnome_web_photo);
	if ($traytheme->has_icon('web-browser')) {
		$menuitem_web->set_image(Gtk3::Image->new_from_icon_name('web-browser', 'menu'));
	} else {
		$menuitem_web->set_image(Gtk3::Image->new_from_pixbuf($lp->load("$shutter_root/share/shutter/resources/icons/web_image.svg", $shf->icon_size('menu'))));
	}
	$menuitem_web->signal_connect(
		activate => \&Shutter::App::evt_take_screenshot,
		'tray_web'
	);

	#show main window
	my $menuitem_show_window = Gtk3::MenuItem->new_with_mnemonic($d->get('S_how main window'));
	$menuitem_show_window->signal_connect('activate', sub { ${$is_hidden_ref} = TRUE; Shutter::App::fct_control_main_window('show'); });
	$menuitem_show_window->set_name('show_window');
	$menuitem_show_window->set_sensitive(TRUE);

	#redo last screenshot
	my $menuitem_redoshot = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('_Redo last screenshot'));
	$menuitem_redoshot->set_image(Gtk3::Image->new_from_stock('gtk-refresh', 'menu'));
	$menuitem_redoshot->signal_connect('activate', \&Shutter::App::evt_take_screenshot, 'redoshot');
	$menuitem_redoshot->set_name('redoshot');
	$menuitem_redoshot->set_sensitive(FALSE);

	#preferences
	my $menuitem_settings = Gtk3::ImageMenuItem->new_from_stock('gtk-preferences');
	$menuitem_settings->signal_connect("activate", \&Shutter::App::evt_show_settings);

	#quick profile selector
	my $menuitem_quicks = Gtk3::MenuItem->new_with_mnemonic($d->get('_Quick profile select'));

	#set name to identify the item later - we use this in really rare cases
	$menuitem_quicks->set_name('quicks');
	$menuitem_quicks->set_sensitive(FALSE);

	#info
	my $menuitem_info = Gtk3::ImageMenuItem->new_from_stock('gtk-about');
	$menuitem_info->signal_connect("activate", \&Shutter::App::evt_about);

	#quit
	my $menuitem_quit = Gtk3::ImageMenuItem->new_from_stock('gtk-quit');
	$menuitem_quit->signal_connect("activate", \&Shutter::App::evt_delete_window, 'quit');

	$menu_tray->append($menuitem_show_window);
	$menu_tray->append(Gtk3::SeparatorMenuItem->new);
	$menu_tray->append($menuitem_redoshot);
	$menu_tray->append(Gtk3::SeparatorMenuItem->new);
	$menu_tray->append($menuitem_select);

	#~ $menu_tray->append( Gtk3::SeparatorMenuItem->new );
	$menu_tray->append($menuitem_full);

	#~ $menu_tray->append( Gtk3::SeparatorMenuItem->new );
	#~ $menu_tray->append($menuitem_awindow);
	$menu_tray->append($menuitem_window);
	$menu_tray->append($menuitem_window_list);

	# No sections for now: https://github.com/shutter-project/shutter/issues/25
	#$menu_tray->append($menuitem_window_sect);
	$menu_tray->append($menuitem_window_menu);
	$menu_tray->append($menuitem_window_tooltip);

	#~ $menu_tray->append( Gtk3::SeparatorMenuItem->new );
	$menu_tray->append($menuitem_web);
	$menu_tray->append(Gtk3::SeparatorMenuItem->new);
	$menu_tray->append($menuitem_settings);
	$menu_tray->append($menuitem_quicks);
	$menu_tray->append(Gtk3::SeparatorMenuItem->new);
	$menu_tray->append($menuitem_info);
	$menu_tray->append($menuitem_quit);
	$menu_tray->show_all;

	return $menu_tray;
}

sub program_menu {
	my ($sc, $shf, $sm, $session_screens, $session_start_screen, $menu_programs) = @_;

	$menu_programs = Gtk3::Menu->new unless defined $menu_programs;
	foreach my $child ($menu_programs->get_children) {
		$child->destroy;
	}

	#take $key (mime) directly
	my $key = Shutter::App::fct_get_current_file();

	#FIXME - different mime types
	#have different apps registered
	#we should restrict the offeres apps
	#by comparing the selected
	#
	#currently we just take the last selected file into account
	#
	#search selected files for mime...
	unless ($key) {
		$session_start_screen->{'first_page'}->{'view'}->selected_foreach(
			sub {
				my ($view, $path) = @_;
				my $iter = $session_start_screen->{'first_page'}->{'model'}->get_iter($path);
				if (defined $iter) {
					$key = $session_start_screen->{'first_page'}->{'model'}->get_value($iter, 2);
				}
			});
	}

	#still no key? => leave sub
	unless ($key) {
		$sm->{_menuitem_reopen}->set_sensitive(FALSE);
		$sm->{_menuitem_large_reopen}->set_sensitive(FALSE);
		return $menu_programs;
	}

	#no valid hash entry?
	unless (exists $session_screens->{$key}->{'mime_type'}) {
		$sm->{_menuitem_reopen}->set_sensitive(FALSE);
		$sm->{_menuitem_large_reopen}->set_sensitive(FALSE);
		return $menu_programs;
	}

	#get applications
	my $mime_type = $session_screens->{$key}->{'mime_type'};

	# apps is a list of GAppInfo
	# https://developer.gnome.org/gio/stable/GAppInfo.html
	my $apps = Glib::IO::AppInfo::get_recommended_for_type($mime_type);

	# $apps is undefined if Glib::IO::AppInfo::get_recommended_for_type fails
	unless (defined $apps) {
		$sm->{_menuitem_reopen}->set_sensitive(FALSE);
		$sm->{_menuitem_large_reopen}->set_sensitive(FALSE);
		return $menu_programs;
	}

	#no apps determined!
	unless (scalar @$apps) {
		$sm->{_menuitem_reopen}->set_sensitive(FALSE);
		$sm->{_menuitem_large_reopen}->set_sensitive(FALSE);
		return $menu_programs;
	}

	#create menu items
	foreach my $app (@$apps) {

		#ignore Shutter's desktop entry
		next if $app->get_display_name =~ /shutter/i;

		# $app->{'name'} = $shf->utf8_decode( $app->{'name'} );

		#FIXME
		#we simply cut the kde* / kde4* substring here
		#is it possible to get the wrong app if there
		#is the kde3 and the kde4 version of an app installed?
		#
		#I think so ;-)
		# $app->{'id'} =~ s/^(kde4|kde)-//g;

		my $program_item = Gtk3::ImageMenuItem->new_with_label($app->get_display_name);
		$program_item->set('always_show_image' => TRUE);
		$menu_programs->append($program_item);

		my $icon = $app->get_icon;
		if ($icon && $program_item) {
			my $icon_pixbuf = undef;
			my ($iw, $ih) = $shf->icon_size('menu');
			eval {
				my $icon_info = $sc->get_theme->choose_icon($icon->get_names, $ih, []);
				$icon_pixbuf = $icon_info->load_icon if $icon_info;
			};
			if ($@) {
				print "\nWARNING: Could not load icon for ", $app->get_display_name, ": $@\n";
				$icon_pixbuf = undef;
			}
			if ($icon_pixbuf) {
				$program_item->set_image(Gtk3::Image->new_from_pixbuf($icon_pixbuf));
			}
		}

		#connect to signal
		if ($program_item) {
			$program_item->signal_connect(
				'activate' => sub {
					Shutter::App::fct_open_with_program($app, $app->get_display_name);
				});
		}
	}

	#menu does not contain any item
	unless ($menu_programs->get_children) {
		$sm->{_menuitem_reopen}->set_sensitive(FALSE);
		$sm->{_menuitem_large_reopen}->set_sensitive(FALSE);
	}

	$menu_programs->show_all;
	return $menu_programs;
}

sub web_menu {
	my ($d, $settings_xml) = @_;

	my $menu_web = Gtk3::Menu->new;

	my $timeout0 = Gtk3::RadioMenuItem->new_with_label(undef,     $d->get("Wait indefinitely"));
	my $timeout1 = Gtk3::RadioMenuItem->new_with_label($timeout0, sprintf($d->nget("Wait max %d second", "Wait max %d seconds", 10), 10));
	my $timeout2 = Gtk3::RadioMenuItem->new_with_label($timeout0, sprintf($d->nget("Wait max %d second", "Wait max %d seconds", 10), 30));
	my $timeout3 = Gtk3::RadioMenuItem->new_with_label($timeout0, sprintf($d->nget("Wait max %d minute", "Wait max %d minutes", 1),  1));
	my $timeout4 = Gtk3::RadioMenuItem->new_with_label($timeout0, sprintf($d->nget("Wait max %d minute", "Wait max %d minutes", 2),  2));

	$timeout0->set_name("timeout0");
	$timeout1->set_name("timeout10");
	$timeout2->set_name("timeout30");
	$timeout3->set_name("timeout60");
	$timeout4->set_name("timeout120");

	$timeout0->set_tooltip_text($d->get("Shutter will wait indefinitely for the screenshot to capture"));
	$timeout1->set_tooltip_text(
		sprintf(
			$d->nget(
				"Shutter will wait up to %d second for the screenshot to capture before aborting the process if it's taking too long",
				"Shutter will wait up to %d seconds for the screenshot to capture before aborting the process if it's taking too long",
				10
			),
			10
		));
	$timeout2->set_tooltip_text(
		sprintf(
			$d->nget(
				"Shutter will wait up to %d second for the screenshot to capture before aborting the process if it's taking too long",
				"Shutter will wait up to %d seconds for the screenshot to capture before aborting the process if it's taking too long",
				30
			),
			30
		));
	$timeout3->set_tooltip_text(
		sprintf(
			$d->nget(
				"Shutter will wait up to %d minute for the screenshot to capture before aborting the process if it's taking too long",
				"Shutter will wait up to %d minutes for the screenshot to capture before aborting the process if it's taking too long",
				1
			),
			1
		));
	$timeout4->set_tooltip_text(
		sprintf(
			$d->nget(
				"Shutter will wait up to %d minute for the screenshot to capture before aborting the process if it's taking too long",
				"Shutter will wait up to %d minutes for the screenshot to capture before aborting the process if it's taking too long",
				2
			),
			2
		));

	$timeout2->set_active(TRUE);
	$menu_web->append($timeout0);
	$menu_web->append($timeout1);
	$menu_web->append($timeout2);
	$menu_web->append($timeout3);
	$menu_web->append($timeout4);

	if (defined $settings_xml->{'general'}->{'web_timeout'}) {

		#determining timeout
		my @timeouts = $menu_web->get_children;
		my $timeout  = undef;
		foreach my $to (@timeouts) {
			$timeout = $to->get_name;
			$timeout =~ /([0-9]+)/;
			$timeout = $1;
			if ($settings_xml->{'general'}->{'web_timeout'} == $timeout) {
				$to->set_active(TRUE);
			}
		}
	}
	$menu_web->show_all;
	return $menu_web;
}

sub profile_menu {
	my $current_profile_indx_ref   = shift;
	my $combobox_settings_profiles = shift;
	my $current_profiles_ref       = shift;
	my $menu_profile               = shift;

	$menu_profile = Gtk3::Menu->new unless defined $menu_profile;
	foreach my $child ($menu_profile->get_children) {
		$child->destroy;
	}

	my $group   = undef;
	my $counter = 0;
	foreach my $profile (@{$current_profiles_ref}) {
		my $profile_item = Gtk3::RadioMenuItem->new_with_label($group, $profile);
		$profile_item->set_active(TRUE)
			if $profile eq $combobox_settings_profiles->get_active_text;
		$profile_item->signal_connect(
			'toggled' => sub {
				my $widget = shift;
				return TRUE unless $widget->get_active;

				for (my $i = 0 ; $i < scalar @{$current_profiles_ref} ; $i++) {
					$combobox_settings_profiles->set_active($i);
					${$current_profile_indx_ref} = $i;
					if ($profile eq $combobox_settings_profiles->get_active_text) {
						Shutter::App::evt_apply_profile($widget, $combobox_settings_profiles, $current_profiles_ref);
						last;
					}
				}
			});
		$group = $profile_item unless $group;
		$menu_profile->append($profile_item);
		$counter++;
	}

	$menu_profile->show_all;
	return $menu_profile;
}

1;