runitx Claude Opus 5.5 commited on
Commit
048541b
·
unverified ·
1 Parent(s): bc44c86

Extract context menu builders into Shutter::App::ContextMenus

Browse files

Move fct_ret_{workspace,window,tray,program,web,profile}_menu out of
bin/shutter. One-line wrappers with the original names pass the former
file-scoped globals explicitly; globals the menus assign to
($current_monitor_active, $is_hidden, $current_profile_indx) are passed
as scalar refs. Callbacks still dispatch to Shutter::App::evt_*/fct_*.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

bin/shutter CHANGED
@@ -8002,668 +8002,19 @@ modes are currently experimental, your desktop environment might fall back to an
8002
  return TRUE;
8003
  }
8004
 
8005
- sub fct_ret_workspace_menu {
8006
- my $init = shift;
8007
-
8008
- my $menu_wrksp = Gtk3::Menu->new;
8009
- unless ($x11_supported) {
8010
-
8011
- #On Wayland we can't enumerate workspaces via libwnck, but we can still
8012
- #offer to capture a single monitor by cropping the portal screenshot.
8013
- my $gdk_screen = Gtk3::Gdk::Screen::get_default;
8014
- my $n_mons = $gdk_screen->get_n_monitors;
8015
- if ($n_mons > 1) {
8016
- for (my $i = 0 ; $i < $n_mons ; $i++) {
8017
- my $geo = $gdk_screen->get_monitor_geometry($i);
8018
- my $plug = eval { $gdk_screen->get_monitor_plug_name($i) };
8019
- my $label = $plug
8020
- ? sprintf("%s (%dx%d)", $plug, $geo->{width}, $geo->{height})
8021
- : sprintf($d->get("Monitor %d (%dx%d)"), $i + 1, $geo->{width}, $geo->{height});
8022
- my $mon_item = Gtk3::MenuItem->new_with_label($label);
8023
- $mon_item->signal_connect('activate' => \&evt_take_screenshot, "shutter_monitor_direct$i");
8024
- $menu_wrksp->append($mon_item);
8025
- }
8026
- $menu_wrksp->show_all;
8027
- }
8028
- return $menu_wrksp;
8029
- }
8030
-
8031
- my $wnck_screen = Wnck::Screen::get_default();
8032
- unless ($wnck_screen) {
8033
- $current_monitor_active = Gtk3::CheckMenuItem->new_with_label($d->get("Limit to current monitor"));
8034
- return $menu_wrksp;
8035
- }
8036
- $wnck_screen->force_update();
8037
-
8038
- #we determine the wm name but on older
8039
- #version of libwnck (or the bindings)
8040
- #the needed method is not available
8041
- #in this case we use gdk to do it
8042
- #
8043
- #this leads to a known problem when switching
8044
- #the wm => wm_name will still remain the old one
8045
- #but it doesn't work on gtk3
8046
- my $wm_name;
8047
- if ($wnck_screen->can('get_window_manager_name')) {
8048
- $wm_name = $wnck_screen->get_window_manager_name;
8049
- }
8050
-
8051
- my $active_workspace = $wnck_screen->get_active_workspace;
8052
-
8053
- #we need to handle different window managers here because there are some different models related
8054
- #to workspaces and viewports
8055
- # compiz uses "multiple workspaces" - "multiple viewports" model for example
8056
- # default gnome wm metacity simply uses multiple workspaces
8057
- #we will try to handle them by name
8058
- my @workspaces = ();
8059
- for (my $wcount = 0 ; $wcount < $wnck_screen->get_workspace_count ; $wcount++) {
8060
- push(@workspaces, $wnck_screen->get_workspace($wcount));
8061
- }
8062
-
8063
- foreach my $space (@workspaces) {
8064
- next unless defined $space;
8065
-
8066
- #compiz
8067
- print "Current window manager: ", $wm_name, "\n" if $sc->get_debug;
8068
- if ($wm_name =~ /compiz/i) {
8069
 
8070
- #calculate viewports with size of workspace
8071
- my $vpx = $space->get_viewport_x;
8072
- my $vpy = $space->get_viewport_y;
8073
 
8074
- my $n_viewports_column = int($space->get_width / $wnck_screen->get_width);
8075
- my $n_viewports_rows = int($space->get_height / $wnck_screen->get_height);
8076
 
8077
- #rows
8078
- for (my $j = 0 ; $j < $n_viewports_rows ; $j++) {
8079
 
8080
- #columns
8081
- for (my $i = 0 ; $i < $n_viewports_column ; $i++) {
8082
- my @vp = ($i * $wnck_screen->get_width, $j * $wnck_screen->get_height);
8083
- my $vp_name = "$wm_name x: $i y: $j";
8084
-
8085
- print "shutter_wrksp_direct_compiz" . $vp[0] . "x" . $vp[1] . "\n"
8086
- if $sc->get_debug;
8087
-
8088
- my $vp_item = Gtk3::MenuItem->new_with_label(ucfirst $vp_name);
8089
- $vp_item->signal_connect(
8090
- 'activate' => \&evt_take_screenshot,
8091
- "shutter_wrksp_direct_compiz" . $vp[0] . "x" . $vp[1]);
8092
- $menu_wrksp->append($vp_item);
8093
-
8094
- #do not offer current viewport
8095
- if ($vp[0] == $vpx && $vp[1] == $vpy) {
8096
- $vp_item->set_sensitive(FALSE);
8097
- }
8098
- } #columns
8099
- } #rows
8100
-
8101
- #all other wm manager like metacity etc.
8102
- #we could add more of them here if needed
8103
- } else {
8104
-
8105
- my $wrkspace_item = Gtk3::MenuItem->new_with_label($space->get_name);
8106
- $wrkspace_item->signal_connect(
8107
- 'activate' => \&evt_take_screenshot,
8108
- "shutter_wrksp_direct" . $space->get_number
8109
- );
8110
- $menu_wrksp->append($wrkspace_item);
8111
-
8112
- if ( $active_workspace
8113
- && $active_workspace->get_number == $space->get_number)
8114
- {
8115
- $wrkspace_item->set_sensitive(FALSE);
8116
- }
8117
-
8118
- }
8119
- }
8120
-
8121
- #entry for capturing all workspaces
8122
- $menu_wrksp->append(Gtk3::SeparatorMenuItem->new);
8123
-
8124
- my $allwspaces_item = Gtk3::MenuItem->new_with_label($d->get("Capture All Workspaces"));
8125
- $allwspaces_item->signal_connect(
8126
- 'activate' => \&evt_take_screenshot,
8127
- "shutter_wrksp_direct" . 'all'
8128
- );
8129
- $menu_wrksp->append($allwspaces_item);
8130
-
8131
- #monitor flag
8132
- my $n_mons = Gtk3::Gdk::Screen::get_default->get_n_monitors;
8133
-
8134
- #use only current monitor
8135
- $menu_wrksp->append(Gtk3::SeparatorMenuItem->new);
8136
- if ($init) {
8137
- $current_monitor_active = Gtk3::CheckMenuItem->new_with_label($d->get("Limit to current monitor"));
8138
- if (defined $settings_xml->{'general'}->{'current_monitor_active'}) {
8139
- $current_monitor_active->set_active($settings_xml->{'general'}->{'current_monitor_active'});
8140
- } else {
8141
- $current_monitor_active->set_active(FALSE);
8142
- }
8143
- $menu_wrksp->append($current_monitor_active);
8144
- } else {
8145
- $current_monitor_active->reparent($menu_wrksp);
8146
- }
8147
-
8148
- $current_monitor_active->set_tooltip_text(
8149
- sprintf(
8150
- $d->nget(
8151
- "This option is only useful when you are running a multi-monitor system (%d monitor detected).\nEnable it to capture only the current monitor.",
8152
- "This option is only useful when you are running a multi-monitor system (%d monitors detected).\nEnable it to capture only the current monitor.",
8153
- $n_mons
8154
- ),
8155
- $n_mons
8156
- ));
8157
- if ($n_mons > 1) {
8158
- $current_monitor_active->set_sensitive(TRUE);
8159
- } else {
8160
- $current_monitor_active->set_active(FALSE);
8161
- $current_monitor_active->set_sensitive(FALSE);
8162
- }
8163
-
8164
- $menu_wrksp->show_all();
8165
- return $menu_wrksp;
8166
- }
8167
-
8168
- sub fct_ret_window_menu {
8169
-
8170
- my $menu_windows = Gtk3::Menu->new;
8171
- return $menu_windows unless $wnck_screen;
8172
-
8173
- my $active_workspace = $wnck_screen->get_active_workspace;
8174
- my $icontheme = $sc->get_theme;
8175
-
8176
- #add item for active window
8177
- my $active_window_item_image;
8178
- if ($icontheme->has_icon('preferences-system-windows')) {
8179
- $active_window_item_image = Gtk3::Image->new_from_icon_name('preferences-system-windows', 'menu');
8180
- } else {
8181
- $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')));
8182
- }
8183
 
8184
- my $active_window_item = Gtk3::ImageMenuItem->new_with_label($d->get("Active Window"));
8185
- $active_window_item->set_image($active_window_item_image);
8186
- $active_window_item->set('always_show_image' => TRUE);
8187
 
8188
- $active_window_item->set_tooltip_text($d->get("Capture the last active window"));
8189
-
8190
- $active_window_item->signal_connect(
8191
- 'activate' => \&evt_take_screenshot,
8192
- 'awindow'
8193
- );
8194
-
8195
- $menu_windows->append($active_window_item);
8196
- $menu_windows->append(Gtk3::SeparatorMenuItem->new);
8197
-
8198
- # Check if we can retrieve the list of stacked windows first, otherwise we will run into a crash, see issue 659
8199
-
8200
- unless ($wnck_screen->get_windows_stacked) {
8201
- print "ERROR: The window list could not be retrieved and has been disabled, see https://github.com/shutter-project/shutter/issues/659";
8202
- return $menu_windows;
8203
- }
8204
-
8205
- #add all windows to menu to capture it directly
8206
-
8207
- foreach my $win (@{$wnck_screen->get_windows_stacked}) {
8208
- if ($active_workspace && $win->is_on_workspace($active_workspace)) {
8209
- my $win_name = $win->get_name;
8210
- Encode::_utf8_on($win_name);
8211
- my $window_item = Gtk3::ImageMenuItem->new_with_label($win_name);
8212
- foreach my $child ($window_item->get_children) {
8213
- if ($child =~ /Gtk3::AccelLabel/) {
8214
- $child->set_width_chars(50);
8215
- $child->set_ellipsize('middle');
8216
- last;
8217
- }
8218
- }
8219
- $window_item->set_image(Gtk3::Image->new_from_pixbuf($win->get_mini_icon));
8220
- $window_item->set('always_show_image' => TRUE);
8221
- $window_item->signal_connect(
8222
- 'activate' => \&evt_take_screenshot,
8223
- "shutter_window_direct" . $win->get_xid
8224
- );
8225
- $menu_windows->append($window_item);
8226
- }
8227
- }
8228
-
8229
- $menu_windows->show_all;
8230
- return $menu_windows;
8231
- }
8232
-
8233
- sub fct_ret_tray_menu {
8234
-
8235
- my $traytheme = $sc->get_theme;
8236
-
8237
- my $menu_tray = Gtk3::Menu->new();
8238
-
8239
- #selection
8240
- my $menuitem_select = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('_Selection'));
8241
- # served via interactive XDG portal on Wayland too
8242
- $menuitem_select->set_sensitive(TRUE);
8243
- eval {
8244
- my $ccursor_pb = Gtk3::Gdk::Cursor::new('left_ptr')->get_image->scale_simple($shf->icon_size('menu'), 'bilinear');
8245
- $menuitem_select->set_image(Gtk3::Image->new_from_pixbuf($ccursor_pb));
8246
- };
8247
- if ($@) {
8248
- if ($traytheme->has_icon('applications-accessories')) {
8249
- $menuitem_select->set_image(Gtk3::Image->new_from_icon_name('applications-accessories', 'menu'));
8250
- } else {
8251
- $menuitem_select->set_image(Gtk3::Image->new_from_pixbuf($lp->load("$shutter_root/share/shutter/resources/icons/selection.svg", $shf->icon_size('menu'))));
8252
- }
8253
- }
8254
- $menuitem_select->signal_connect(
8255
- activate => \&evt_take_screenshot,
8256
- 'tray_select'
8257
- );
8258
-
8259
- #full screen
8260
- my $menuitem_full = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('_Desktop'));
8261
- if ($traytheme->has_icon('user-desktop')) {
8262
- $menuitem_full->set_image(Gtk3::Image->new_from_icon_name('user-desktop', 'menu'));
8263
- } elsif ($traytheme->has_icon('desktop')) {
8264
- $menuitem_full->set_image(Gtk3::Image->new_from_icon_name('desktop', 'menu'));
8265
- } else {
8266
- $menuitem_full->set_image(Gtk3::Image->new_from_pixbuf($lp->load("$shutter_root/share/shutter/resources/icons/desktop.svg", $shf->icon_size('menu'))));
8267
- }
8268
- $menuitem_full->signal_connect(
8269
- activate => \&evt_take_screenshot,
8270
- 'tray_full'
8271
- );
8272
-
8273
- #~ #awindow
8274
- #~ my $menuitem_awindow = Gtk3::ImageMenuItem->new_with_mnemonic( $d->get('_Active Window') );
8275
- #~ if($traytheme->has_icon('preferences-system-windows')){
8276
- #~ $menuitem_awindow->set_image( Gtk3::Image->new_from_icon_name( 'preferences-system-windows', 'menu' ) );
8277
- #~ }else{
8278
- #~ $menuitem_awindow->set_image(
8279
- #~ Gtk3::Image->new_from_pixbuf(
8280
- #~ $lp->load( "$shutter_root/share/shutter/resources/icons/sel_window_active.svg", $shf->icon_size('menu') )
8281
- #~ )
8282
- #~ );
8283
- #~ }
8284
- #~ $menuitem_awindow->signal_connect(
8285
- #~ activate => \&evt_take_screenshot,
8286
- #~ 'tray_awindow'
8287
- #~ );
8288
-
8289
- #window
8290
- my $menuitem_window = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('Window _under Cursor'));
8291
- # served via interactive XDG portal on Wayland too
8292
- $menuitem_window->set_sensitive(TRUE);
8293
- if ($traytheme->has_icon('preferences-system-windows')) {
8294
- $menuitem_window->set_image(Gtk3::Image->new_from_icon_name('preferences-system-windows', 'menu'));
8295
- } else {
8296
- $menuitem_window->set_image(Gtk3::Image->new_from_pixbuf($lp->load("$shutter_root/share/shutter/resources/icons/sel_window.svg", $shf->icon_size('menu'))));
8297
- }
8298
- $menuitem_window->signal_connect(
8299
- activate => \&evt_take_screenshot,
8300
- 'tray_window'
8301
- );
8302
-
8303
- #window list
8304
- my $menuitem_window_list = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('Select W_indow'));
8305
- $menuitem_window_list->set_sensitive($x11_supported);
8306
- if ($traytheme->has_icon('preferences-system-windows')) {
8307
- $menuitem_window_list->set_image(Gtk3::Image->new_from_icon_name('preferences-system-windows', 'menu'));
8308
- } else {
8309
- $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'))));
8310
- }
8311
- $menuitem_window_list->set_name('windowlist');
8312
- $menuitem_window_list->set_submenu(fct_ret_window_menu());
8313
-
8314
- #section
8315
- # No sections for now: https://github.com/shutter-project/shutter/issues/25
8316
- #my $menuitem_window_sect = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('Se_ction'));
8317
- #if ($traytheme->has_icon('gdm-xnest')) {
8318
- # $menuitem_window_sect->set_image(Gtk3::Image->new_from_icon_name('gdm-xnest', 'menu'));
8319
- #} else {
8320
- # $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'))));
8321
- #}
8322
- #$menuitem_window_sect->signal_connect(
8323
- # activate => \&evt_take_screenshot,
8324
- # 'tray_section'
8325
- #);
8326
-
8327
- #menu
8328
- my $menuitem_window_menu = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('_Menu'));
8329
- $menuitem_window_menu->set_sensitive($x11_supported);
8330
- if ($traytheme->has_icon('alacarte')) {
8331
- $menuitem_window_menu->set_image(Gtk3::Image->new_from_icon_name('alacarte', 'menu'));
8332
- } else {
8333
- $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'))));
8334
- }
8335
- $menuitem_window_menu->signal_connect(
8336
- activate => \&evt_take_screenshot,
8337
- 'tray_menu'
8338
- );
8339
-
8340
- #tooltip
8341
- my $menuitem_window_tooltip = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('_Tooltip'));
8342
- $menuitem_window_tooltip->set_sensitive($x11_supported);
8343
- if ($traytheme->has_icon('help-faq')) {
8344
- $menuitem_window_tooltip->set_image(Gtk3::Image->new_from_icon_name('help-faq', 'menu'));
8345
- } else {
8346
- $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'))));
8347
- }
8348
- $menuitem_window_tooltip->signal_connect(
8349
- activate => \&evt_take_screenshot,
8350
- 'tray_tooltip'
8351
- );
8352
-
8353
- #web
8354
- my $menuitem_web = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('_Web'));
8355
- $menuitem_web->set_sensitive($gnome_web_photo);
8356
- if ($traytheme->has_icon('web-browser')) {
8357
- $menuitem_web->set_image(Gtk3::Image->new_from_icon_name('web-browser', 'menu'));
8358
- } else {
8359
- $menuitem_web->set_image(Gtk3::Image->new_from_pixbuf($lp->load("$shutter_root/share/shutter/resources/icons/web_image.svg", $shf->icon_size('menu'))));
8360
- }
8361
- $menuitem_web->signal_connect(
8362
- activate => \&evt_take_screenshot,
8363
- 'tray_web'
8364
- );
8365
-
8366
- #show main window
8367
- my $menuitem_show_window = Gtk3::MenuItem->new_with_mnemonic($d->get('S_how main window'));
8368
- $menuitem_show_window->signal_connect('activate', sub { $is_hidden = TRUE; fct_control_main_window('show'); });
8369
- $menuitem_show_window->set_name('show_window');
8370
- $menuitem_show_window->set_sensitive(TRUE);
8371
-
8372
- #redo last screenshot
8373
- my $menuitem_redoshot = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('_Redo last screenshot'));
8374
- $menuitem_redoshot->set_image(Gtk3::Image->new_from_stock('gtk-refresh', 'menu'));
8375
- $menuitem_redoshot->signal_connect('activate', \&evt_take_screenshot, 'redoshot');
8376
- $menuitem_redoshot->set_name('redoshot');
8377
- $menuitem_redoshot->set_sensitive(FALSE);
8378
-
8379
- #preferences
8380
- my $menuitem_settings = Gtk3::ImageMenuItem->new_from_stock('gtk-preferences');
8381
- $menuitem_settings->signal_connect("activate", \&evt_show_settings);
8382
-
8383
- #quick profile selector
8384
- my $menuitem_quicks = Gtk3::MenuItem->new_with_mnemonic($d->get('_Quick profile select'));
8385
-
8386
- #set name to identify the item later - we use this in really rare cases
8387
- $menuitem_quicks->set_name('quicks');
8388
- $menuitem_quicks->set_sensitive(FALSE);
8389
-
8390
- #info
8391
- my $menuitem_info = Gtk3::ImageMenuItem->new_from_stock('gtk-about');
8392
- $menuitem_info->signal_connect("activate", \&evt_about);
8393
-
8394
- #quit
8395
- my $menuitem_quit = Gtk3::ImageMenuItem->new_from_stock('gtk-quit');
8396
- $menuitem_quit->signal_connect("activate", \&evt_delete_window, 'quit');
8397
-
8398
- $menu_tray->append($menuitem_show_window);
8399
- $menu_tray->append(Gtk3::SeparatorMenuItem->new);
8400
- $menu_tray->append($menuitem_redoshot);
8401
- $menu_tray->append(Gtk3::SeparatorMenuItem->new);
8402
- $menu_tray->append($menuitem_select);
8403
-
8404
- #~ $menu_tray->append( Gtk3::SeparatorMenuItem->new );
8405
- $menu_tray->append($menuitem_full);
8406
-
8407
- #~ $menu_tray->append( Gtk3::SeparatorMenuItem->new );
8408
- #~ $menu_tray->append($menuitem_awindow);
8409
- $menu_tray->append($menuitem_window);
8410
- $menu_tray->append($menuitem_window_list);
8411
- # No sections for now: https://github.com/shutter-project/shutter/issues/25
8412
- #$menu_tray->append($menuitem_window_sect);
8413
- $menu_tray->append($menuitem_window_menu);
8414
- $menu_tray->append($menuitem_window_tooltip);
8415
-
8416
- #~ $menu_tray->append( Gtk3::SeparatorMenuItem->new );
8417
- $menu_tray->append($menuitem_web);
8418
- $menu_tray->append(Gtk3::SeparatorMenuItem->new);
8419
- $menu_tray->append($menuitem_settings);
8420
- $menu_tray->append($menuitem_quicks);
8421
- $menu_tray->append(Gtk3::SeparatorMenuItem->new);
8422
- $menu_tray->append($menuitem_info);
8423
- $menu_tray->append($menuitem_quit);
8424
- $menu_tray->show_all;
8425
-
8426
- return $menu_tray;
8427
- }
8428
-
8429
- sub fct_ret_program_menu {
8430
- my $menu_programs = shift;
8431
-
8432
- $menu_programs = Gtk3::Menu->new unless defined $menu_programs;
8433
- foreach my $child ($menu_programs->get_children) {
8434
- $child->destroy;
8435
- }
8436
-
8437
- #take $key (mime) directly
8438
- my $key = fct_get_current_file();
8439
-
8440
- #FIXME - different mime types
8441
- #have different apps registered
8442
- #we should restrict the offeres apps
8443
- #by comparing the selected
8444
- #
8445
- #currently we just take the last selected file into account
8446
- #
8447
- #search selected files for mime...
8448
- unless ($key) {
8449
- $session_start_screen{'first_page'}->{'view'}->selected_foreach(
8450
- sub {
8451
- my ($view, $path) = @_;
8452
- my $iter = $session_start_screen{'first_page'}->{'model'}->get_iter($path);
8453
- if (defined $iter) {
8454
- $key = $session_start_screen{'first_page'}->{'model'}->get_value($iter, 2);
8455
- }
8456
- });
8457
- }
8458
-
8459
- #still no key? => leave sub
8460
- unless ($key) {
8461
- $sm->{_menuitem_reopen}->set_sensitive(FALSE);
8462
- $sm->{_menuitem_large_reopen}->set_sensitive(FALSE);
8463
- return $menu_programs;
8464
- }
8465
-
8466
- #no valid hash entry?
8467
- unless (exists $session_screens{$key}->{'mime_type'}) {
8468
- $sm->{_menuitem_reopen}->set_sensitive(FALSE);
8469
- $sm->{_menuitem_large_reopen}->set_sensitive(FALSE);
8470
- return $menu_programs;
8471
- }
8472
-
8473
- #get applications
8474
- my $mime_type = $session_screens{$key}->{'mime_type'};
8475
-
8476
- # apps is a list of GAppInfo
8477
- # https://developer.gnome.org/gio/stable/GAppInfo.html
8478
- my $apps = Glib::IO::AppInfo::get_recommended_for_type($mime_type);
8479
-
8480
- # $apps is undefined if Glib::IO::AppInfo::get_recommended_for_type fails
8481
- unless (defined $apps) {
8482
- $sm->{_menuitem_reopen}->set_sensitive(FALSE);
8483
- $sm->{_menuitem_large_reopen}->set_sensitive(FALSE);
8484
- return $menu_programs;
8485
- }
8486
-
8487
- #no apps determined!
8488
- unless (scalar @$apps) {
8489
- $sm->{_menuitem_reopen}->set_sensitive(FALSE);
8490
- $sm->{_menuitem_large_reopen}->set_sensitive(FALSE);
8491
- return $menu_programs;
8492
- }
8493
-
8494
- #create menu items
8495
- foreach my $app (@$apps) {
8496
-
8497
- #ignore Shutter's desktop entry
8498
- next if $app->get_display_name =~ /shutter/i;
8499
-
8500
- # $app->{'name'} = $shf->utf8_decode( $app->{'name'} );
8501
-
8502
- #FIXME
8503
- #we simply cut the kde* / kde4* substring here
8504
- #is it possible to get the wrong app if there
8505
- #is the kde3 and the kde4 version of an app installed?
8506
- #
8507
- #I think so ;-)
8508
- # $app->{'id'} =~ s/^(kde4|kde)-//g;
8509
-
8510
- my $program_item = Gtk3::ImageMenuItem->new_with_label($app->get_display_name);
8511
- $program_item->set('always_show_image' => TRUE);
8512
- $menu_programs->append($program_item);
8513
-
8514
- my $icon = $app->get_icon;
8515
- if ($icon && $program_item) {
8516
- my $icon_pixbuf = undef;
8517
- my ($iw, $ih) = $shf->icon_size('menu');
8518
- eval {
8519
- my $icon_info = $sc->get_theme->choose_icon($icon->get_names, $ih, []);
8520
- $icon_pixbuf = $icon_info->load_icon if $icon_info;
8521
- };
8522
- if ($@) {
8523
- print "\nWARNING: Could not load icon for ", $app->get_display_name, ": $@\n";
8524
- $icon_pixbuf = undef;
8525
- }
8526
- if ($icon_pixbuf) {
8527
- $program_item->set_image(Gtk3::Image->new_from_pixbuf($icon_pixbuf));
8528
- }
8529
- }
8530
-
8531
- #connect to signal
8532
- if ($program_item) {
8533
- $program_item->signal_connect(
8534
- 'activate' => sub {
8535
- fct_open_with_program($app, $app->get_display_name);
8536
- });
8537
- }
8538
- }
8539
-
8540
- #menu does not contain any item
8541
- unless ($menu_programs->get_children) {
8542
- $sm->{_menuitem_reopen}->set_sensitive(FALSE);
8543
- $sm->{_menuitem_large_reopen}->set_sensitive(FALSE);
8544
- }
8545
-
8546
- $menu_programs->show_all;
8547
- return $menu_programs;
8548
- }
8549
-
8550
- sub fct_ret_web_menu {
8551
-
8552
- my $menu_web = Gtk3::Menu->new;
8553
-
8554
- my $timeout0 = Gtk3::RadioMenuItem->new_with_label(undef, $d->get("Wait indefinitely"));
8555
- my $timeout1 = Gtk3::RadioMenuItem->new_with_label($timeout0, sprintf($d->nget("Wait max %d second", "Wait max %d seconds", 10), 10));
8556
- my $timeout2 = Gtk3::RadioMenuItem->new_with_label($timeout0, sprintf($d->nget("Wait max %d second", "Wait max %d seconds", 10), 30));
8557
- my $timeout3 = Gtk3::RadioMenuItem->new_with_label($timeout0, sprintf($d->nget("Wait max %d minute", "Wait max %d minutes", 1), 1));
8558
- my $timeout4 = Gtk3::RadioMenuItem->new_with_label($timeout0, sprintf($d->nget("Wait max %d minute", "Wait max %d minutes", 2), 2));
8559
-
8560
- $timeout0->set_name("timeout0");
8561
- $timeout1->set_name("timeout10");
8562
- $timeout2->set_name("timeout30");
8563
- $timeout3->set_name("timeout60");
8564
- $timeout4->set_name("timeout120");
8565
-
8566
- $timeout0->set_tooltip_text($d->get("Shutter will wait indefinitely for the screenshot to capture"));
8567
- $timeout1->set_tooltip_text(
8568
- sprintf(
8569
- $d->nget(
8570
- "Shutter will wait up to %d second for the screenshot to capture before aborting the process if it's taking too long",
8571
- "Shutter will wait up to %d seconds for the screenshot to capture before aborting the process if it's taking too long",
8572
- 10
8573
- ),
8574
- 10
8575
- ));
8576
- $timeout2->set_tooltip_text(
8577
- sprintf(
8578
- $d->nget(
8579
- "Shutter will wait up to %d second for the screenshot to capture before aborting the process if it's taking too long",
8580
- "Shutter will wait up to %d seconds for the screenshot to capture before aborting the process if it's taking too long",
8581
- 30
8582
- ),
8583
- 30
8584
- ));
8585
- $timeout3->set_tooltip_text(
8586
- sprintf(
8587
- $d->nget(
8588
- "Shutter will wait up to %d minute for the screenshot to capture before aborting the process if it's taking too long",
8589
- "Shutter will wait up to %d minutes for the screenshot to capture before aborting the process if it's taking too long",
8590
- 1
8591
- ),
8592
- 1
8593
- ));
8594
- $timeout4->set_tooltip_text(
8595
- sprintf(
8596
- $d->nget(
8597
- "Shutter will wait up to %d minute for the screenshot to capture before aborting the process if it's taking too long",
8598
- "Shutter will wait up to %d minutes for the screenshot to capture before aborting the process if it's taking too long",
8599
- 2
8600
- ),
8601
- 2
8602
- ));
8603
-
8604
- $timeout2->set_active(TRUE);
8605
- $menu_web->append($timeout0);
8606
- $menu_web->append($timeout1);
8607
- $menu_web->append($timeout2);
8608
- $menu_web->append($timeout3);
8609
- $menu_web->append($timeout4);
8610
-
8611
- if (defined $settings_xml->{'general'}->{'web_timeout'}) {
8612
-
8613
- #determining timeout
8614
- my @timeouts = $menu_web->get_children;
8615
- my $timeout = undef;
8616
- foreach my $to (@timeouts) {
8617
- $timeout = $to->get_name;
8618
- $timeout =~ /([0-9]+)/;
8619
- $timeout = $1;
8620
- if ($settings_xml->{'general'}->{'web_timeout'} == $timeout) {
8621
- $to->set_active(TRUE);
8622
- }
8623
- }
8624
- }
8625
- $menu_web->show_all;
8626
- return $menu_web;
8627
- }
8628
-
8629
- sub fct_ret_profile_menu {
8630
- my $combobox_settings_profiles = shift;
8631
- my $current_profiles_ref = shift;
8632
- my $menu_profile = shift;
8633
-
8634
- $menu_profile = Gtk3::Menu->new unless defined $menu_profile;
8635
- foreach my $child ($menu_profile->get_children) {
8636
- $child->destroy;
8637
- }
8638
-
8639
- my $group = undef;
8640
- my $counter = 0;
8641
- foreach my $profile (@{$current_profiles_ref}) {
8642
- my $profile_item = Gtk3::RadioMenuItem->new_with_label($group, $profile);
8643
- $profile_item->set_active(TRUE)
8644
- if $profile eq $combobox_settings_profiles->get_active_text;
8645
- $profile_item->signal_connect(
8646
- 'toggled' => sub {
8647
- my $widget = shift;
8648
- return TRUE unless $widget->get_active;
8649
-
8650
- for (my $i = 0 ; $i < scalar @{$current_profiles_ref} ; $i++) {
8651
- $combobox_settings_profiles->set_active($i);
8652
- $current_profile_indx = $i;
8653
- if ($profile eq $combobox_settings_profiles->get_active_text) {
8654
- evt_apply_profile($widget, $combobox_settings_profiles, $current_profiles_ref);
8655
- last;
8656
- }
8657
- }
8658
- });
8659
- $group = $profile_item unless $group;
8660
- $menu_profile->append($profile_item);
8661
- $counter++;
8662
- }
8663
-
8664
- $menu_profile->show_all;
8665
- return $menu_profile;
8666
- }
8667
 
8668
  sub fct_load_accounts_tree {
8669
 
 
8002
  return TRUE;
8003
  }
8004
 
8005
+ require Shutter::App::ContextMenus;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8006
 
8007
+ sub fct_ret_workspace_menu { return Shutter::App::ContextMenus::workspace_menu($sc, $d, $settings_xml, $x11_supported, \$current_monitor_active, @_) }
 
 
8008
 
8009
+ sub fct_ret_window_menu { return Shutter::App::ContextMenus::window_menu($sc, $d, $lp, $shf, $shutter_root, $wnck_screen, @_) }
 
8010
 
8011
+ sub fct_ret_tray_menu { return Shutter::App::ContextMenus::tray_menu($sc, $d, $lp, $shf, $shutter_root, $x11_supported, $gnome_web_photo, \$is_hidden, @_) }
 
8012
 
8013
+ sub fct_ret_program_menu { return Shutter::App::ContextMenus::program_menu($sc, $shf, $sm, \%session_screens, \%session_start_screen, @_) }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8014
 
8015
+ sub fct_ret_web_menu { return Shutter::App::ContextMenus::web_menu($d, $settings_xml, @_) }
 
 
8016
 
8017
+ sub fct_ret_profile_menu { return Shutter::App::ContextMenus::profile_menu(\$current_profile_indx, @_) }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8018
 
8019
  sub fct_load_accounts_tree {
8020
 
share/shutter/resources/modules/Shutter/App/ContextMenus.pm ADDED
@@ -0,0 +1,718 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ###################################################
2
+ #
3
+ # Copyright (C) 2008-2013 Mario Kemper <mario.kemper@gmail.com>
4
+ #
5
+ # This file is part of Shutter.
6
+ #
7
+ # Shutter is free software; you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation; either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # Shutter is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with Shutter; if not, write to the Free Software
19
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
+ #
21
+ ###################################################
22
+
23
+ package Shutter::App::ContextMenus;
24
+
25
+ #Builders for Shutter's context/popup menus (workspace, window list,
26
+ #tray icon, "open with" programs, web timeout and quick profile select).
27
+ #
28
+ #These used to be fct_ret_*_menu subs in bin/shutter. bin/shutter keeps
29
+ #thin wrappers with the original names that pass the former file-scoped
30
+ #globals explicitly. Globals that the menus assign to (directly or from a
31
+ #callback) are passed as scalar references. Callbacks still dispatch to
32
+ #evt_*/fct_* subs that live in package Shutter::App.
33
+
34
+ #modules
35
+ #--------------------------------------
36
+ use utf8;
37
+ use strict;
38
+ use warnings;
39
+ use Gtk3;
40
+ use Encode;
41
+
42
+ #Glib
43
+ use Glib qw/TRUE FALSE/;
44
+
45
+ #--------------------------------------
46
+
47
+ sub workspace_menu {
48
+ my ($sc, $d, $settings_xml, $x11_supported, $current_monitor_active_ref, $init) = @_;
49
+
50
+ my $menu_wrksp = Gtk3::Menu->new;
51
+ unless ($x11_supported) {
52
+
53
+ #On Wayland we can't enumerate workspaces via libwnck, but we can still
54
+ #offer to capture a single monitor by cropping the portal screenshot.
55
+ my $gdk_screen = Gtk3::Gdk::Screen::get_default;
56
+ my $n_mons = $gdk_screen->get_n_monitors;
57
+ if ($n_mons > 1) {
58
+ for (my $i = 0 ; $i < $n_mons ; $i++) {
59
+ my $geo = $gdk_screen->get_monitor_geometry($i);
60
+ my $plug = eval { $gdk_screen->get_monitor_plug_name($i) };
61
+ my $label =
62
+ $plug
63
+ ? sprintf("%s (%dx%d)", $plug, $geo->{width}, $geo->{height})
64
+ : sprintf($d->get("Monitor %d (%dx%d)"), $i + 1, $geo->{width}, $geo->{height});
65
+ my $mon_item = Gtk3::MenuItem->new_with_label($label);
66
+ $mon_item->signal_connect('activate' => \&Shutter::App::evt_take_screenshot, "shutter_monitor_direct$i");
67
+ $menu_wrksp->append($mon_item);
68
+ }
69
+ $menu_wrksp->show_all;
70
+ }
71
+ return $menu_wrksp;
72
+ }
73
+
74
+ my $wnck_screen = Wnck::Screen::get_default();
75
+ unless ($wnck_screen) {
76
+ ${$current_monitor_active_ref} = Gtk3::CheckMenuItem->new_with_label($d->get("Limit to current monitor"));
77
+ return $menu_wrksp;
78
+ }
79
+ $wnck_screen->force_update();
80
+
81
+ #we determine the wm name but on older
82
+ #version of libwnck (or the bindings)
83
+ #the needed method is not available
84
+ #in this case we use gdk to do it
85
+ #
86
+ #this leads to a known problem when switching
87
+ #the wm => wm_name will still remain the old one
88
+ #but it doesn't work on gtk3
89
+ my $wm_name;
90
+ if ($wnck_screen->can('get_window_manager_name')) {
91
+ $wm_name = $wnck_screen->get_window_manager_name;
92
+ }
93
+
94
+ my $active_workspace = $wnck_screen->get_active_workspace;
95
+
96
+ #we need to handle different window managers here because there are some different models related
97
+ #to workspaces and viewports
98
+ # compiz uses "multiple workspaces" - "multiple viewports" model for example
99
+ # default gnome wm metacity simply uses multiple workspaces
100
+ #we will try to handle them by name
101
+ my @workspaces = ();
102
+ for (my $wcount = 0 ; $wcount < $wnck_screen->get_workspace_count ; $wcount++) {
103
+ push(@workspaces, $wnck_screen->get_workspace($wcount));
104
+ }
105
+
106
+ foreach my $space (@workspaces) {
107
+ next unless defined $space;
108
+
109
+ #compiz
110
+ print "Current window manager: ", $wm_name, "\n" if $sc->get_debug;
111
+ if ($wm_name =~ /compiz/i) {
112
+
113
+ #calculate viewports with size of workspace
114
+ my $vpx = $space->get_viewport_x;
115
+ my $vpy = $space->get_viewport_y;
116
+
117
+ my $n_viewports_column = int($space->get_width / $wnck_screen->get_width);
118
+ my $n_viewports_rows = int($space->get_height / $wnck_screen->get_height);
119
+
120
+ #rows
121
+ for (my $j = 0 ; $j < $n_viewports_rows ; $j++) {
122
+
123
+ #columns
124
+ for (my $i = 0 ; $i < $n_viewports_column ; $i++) {
125
+ my @vp = ($i * $wnck_screen->get_width, $j * $wnck_screen->get_height);
126
+ my $vp_name = "$wm_name x: $i y: $j";
127
+
128
+ print "shutter_wrksp_direct_compiz" . $vp[0] . "x" . $vp[1] . "\n"
129
+ if $sc->get_debug;
130
+
131
+ my $vp_item = Gtk3::MenuItem->new_with_label(ucfirst $vp_name);
132
+ $vp_item->signal_connect(
133
+ 'activate' => \&Shutter::App::evt_take_screenshot,
134
+ "shutter_wrksp_direct_compiz" . $vp[0] . "x" . $vp[1]);
135
+ $menu_wrksp->append($vp_item);
136
+
137
+ #do not offer current viewport
138
+ if ($vp[0] == $vpx && $vp[1] == $vpy) {
139
+ $vp_item->set_sensitive(FALSE);
140
+ }
141
+ } #columns
142
+ } #rows
143
+
144
+ #all other wm manager like metacity etc.
145
+ #we could add more of them here if needed
146
+ } else {
147
+
148
+ my $wrkspace_item = Gtk3::MenuItem->new_with_label($space->get_name);
149
+ $wrkspace_item->signal_connect(
150
+ 'activate' => \&Shutter::App::evt_take_screenshot,
151
+ "shutter_wrksp_direct" . $space->get_number
152
+ );
153
+ $menu_wrksp->append($wrkspace_item);
154
+
155
+ if ( $active_workspace
156
+ && $active_workspace->get_number == $space->get_number)
157
+ {
158
+ $wrkspace_item->set_sensitive(FALSE);
159
+ }
160
+
161
+ }
162
+ }
163
+
164
+ #entry for capturing all workspaces
165
+ $menu_wrksp->append(Gtk3::SeparatorMenuItem->new);
166
+
167
+ my $allwspaces_item = Gtk3::MenuItem->new_with_label($d->get("Capture All Workspaces"));
168
+ $allwspaces_item->signal_connect(
169
+ 'activate' => \&Shutter::App::evt_take_screenshot,
170
+ "shutter_wrksp_direct" . 'all'
171
+ );
172
+ $menu_wrksp->append($allwspaces_item);
173
+
174
+ #monitor flag
175
+ my $n_mons = Gtk3::Gdk::Screen::get_default->get_n_monitors;
176
+
177
+ #use only current monitor
178
+ $menu_wrksp->append(Gtk3::SeparatorMenuItem->new);
179
+ if ($init) {
180
+ ${$current_monitor_active_ref} = Gtk3::CheckMenuItem->new_with_label($d->get("Limit to current monitor"));
181
+ if (defined $settings_xml->{'general'}->{'current_monitor_active'}) {
182
+ ${$current_monitor_active_ref}->set_active($settings_xml->{'general'}->{'current_monitor_active'});
183
+ } else {
184
+ ${$current_monitor_active_ref}->set_active(FALSE);
185
+ }
186
+ $menu_wrksp->append(${$current_monitor_active_ref});
187
+ } else {
188
+ ${$current_monitor_active_ref}->reparent($menu_wrksp);
189
+ }
190
+
191
+ ${$current_monitor_active_ref}->set_tooltip_text(
192
+ sprintf(
193
+ $d->nget(
194
+ "This option is only useful when you are running a multi-monitor system (%d monitor detected).\nEnable it to capture only the current monitor.",
195
+ "This option is only useful when you are running a multi-monitor system (%d monitors detected).\nEnable it to capture only the current monitor.",
196
+ $n_mons
197
+ ),
198
+ $n_mons
199
+ ));
200
+ if ($n_mons > 1) {
201
+ ${$current_monitor_active_ref}->set_sensitive(TRUE);
202
+ } else {
203
+ ${$current_monitor_active_ref}->set_active(FALSE);
204
+ ${$current_monitor_active_ref}->set_sensitive(FALSE);
205
+ }
206
+
207
+ $menu_wrksp->show_all();
208
+ return $menu_wrksp;
209
+ }
210
+
211
+ sub window_menu {
212
+ my ($sc, $d, $lp, $shf, $shutter_root, $wnck_screen) = @_;
213
+
214
+ my $menu_windows = Gtk3::Menu->new;
215
+ return $menu_windows unless $wnck_screen;
216
+
217
+ my $active_workspace = $wnck_screen->get_active_workspace;
218
+ my $icontheme = $sc->get_theme;
219
+
220
+ #add item for active window
221
+ my $active_window_item_image;
222
+ if ($icontheme->has_icon('preferences-system-windows')) {
223
+ $active_window_item_image = Gtk3::Image->new_from_icon_name('preferences-system-windows', 'menu');
224
+ } else {
225
+ $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')));
226
+ }
227
+
228
+ my $active_window_item = Gtk3::ImageMenuItem->new_with_label($d->get("Active Window"));
229
+ $active_window_item->set_image($active_window_item_image);
230
+ $active_window_item->set('always_show_image' => TRUE);
231
+
232
+ $active_window_item->set_tooltip_text($d->get("Capture the last active window"));
233
+
234
+ $active_window_item->signal_connect(
235
+ 'activate' => \&Shutter::App::evt_take_screenshot,
236
+ 'awindow'
237
+ );
238
+
239
+ $menu_windows->append($active_window_item);
240
+ $menu_windows->append(Gtk3::SeparatorMenuItem->new);
241
+
242
+ # Check if we can retrieve the list of stacked windows first, otherwise we will run into a crash, see issue 659
243
+
244
+ unless ($wnck_screen->get_windows_stacked) {
245
+ print "ERROR: The window list could not be retrieved and has been disabled, see https://github.com/shutter-project/shutter/issues/659";
246
+ return $menu_windows;
247
+ }
248
+
249
+ #add all windows to menu to capture it directly
250
+
251
+ foreach my $win (@{$wnck_screen->get_windows_stacked}) {
252
+ if ($active_workspace && $win->is_on_workspace($active_workspace)) {
253
+ my $win_name = $win->get_name;
254
+ Encode::_utf8_on($win_name);
255
+ my $window_item = Gtk3::ImageMenuItem->new_with_label($win_name);
256
+ foreach my $child ($window_item->get_children) {
257
+ if ($child =~ /Gtk3::AccelLabel/) {
258
+ $child->set_width_chars(50);
259
+ $child->set_ellipsize('middle');
260
+ last;
261
+ }
262
+ }
263
+ $window_item->set_image(Gtk3::Image->new_from_pixbuf($win->get_mini_icon));
264
+ $window_item->set('always_show_image' => TRUE);
265
+ $window_item->signal_connect(
266
+ 'activate' => \&Shutter::App::evt_take_screenshot,
267
+ "shutter_window_direct" . $win->get_xid
268
+ );
269
+ $menu_windows->append($window_item);
270
+ }
271
+ }
272
+
273
+ $menu_windows->show_all;
274
+ return $menu_windows;
275
+ }
276
+
277
+ sub tray_menu {
278
+ my ($sc, $d, $lp, $shf, $shutter_root, $x11_supported, $gnome_web_photo, $is_hidden_ref) = @_;
279
+
280
+ my $traytheme = $sc->get_theme;
281
+
282
+ my $menu_tray = Gtk3::Menu->new();
283
+
284
+ #selection
285
+ my $menuitem_select = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('_Selection'));
286
+
287
+ # served via interactive XDG portal on Wayland too
288
+ $menuitem_select->set_sensitive(TRUE);
289
+ eval {
290
+ my $ccursor_pb = Gtk3::Gdk::Cursor::new('left_ptr')->get_image->scale_simple($shf->icon_size('menu'), 'bilinear');
291
+ $menuitem_select->set_image(Gtk3::Image->new_from_pixbuf($ccursor_pb));
292
+ };
293
+ if ($@) {
294
+ if ($traytheme->has_icon('applications-accessories')) {
295
+ $menuitem_select->set_image(Gtk3::Image->new_from_icon_name('applications-accessories', 'menu'));
296
+ } else {
297
+ $menuitem_select->set_image(Gtk3::Image->new_from_pixbuf($lp->load("$shutter_root/share/shutter/resources/icons/selection.svg", $shf->icon_size('menu'))));
298
+ }
299
+ }
300
+ $menuitem_select->signal_connect(
301
+ activate => \&Shutter::App::evt_take_screenshot,
302
+ 'tray_select'
303
+ );
304
+
305
+ #full screen
306
+ my $menuitem_full = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('_Desktop'));
307
+ if ($traytheme->has_icon('user-desktop')) {
308
+ $menuitem_full->set_image(Gtk3::Image->new_from_icon_name('user-desktop', 'menu'));
309
+ } elsif ($traytheme->has_icon('desktop')) {
310
+ $menuitem_full->set_image(Gtk3::Image->new_from_icon_name('desktop', 'menu'));
311
+ } else {
312
+ $menuitem_full->set_image(Gtk3::Image->new_from_pixbuf($lp->load("$shutter_root/share/shutter/resources/icons/desktop.svg", $shf->icon_size('menu'))));
313
+ }
314
+ $menuitem_full->signal_connect(
315
+ activate => \&Shutter::App::evt_take_screenshot,
316
+ 'tray_full'
317
+ );
318
+
319
+ #~ #awindow
320
+ #~ my $menuitem_awindow = Gtk3::ImageMenuItem->new_with_mnemonic( $d->get('_Active Window') );
321
+ #~ if($traytheme->has_icon('preferences-system-windows')){
322
+ #~ $menuitem_awindow->set_image( Gtk3::Image->new_from_icon_name( 'preferences-system-windows', 'menu' ) );
323
+ #~ }else{
324
+ #~ $menuitem_awindow->set_image(
325
+ #~ Gtk3::Image->new_from_pixbuf(
326
+ #~ $lp->load( "$shutter_root/share/shutter/resources/icons/sel_window_active.svg", $shf->icon_size('menu') )
327
+ #~ )
328
+ #~ );
329
+ #~ }
330
+ #~ $menuitem_awindow->signal_connect(
331
+ #~ activate => \&Shutter::App::evt_take_screenshot,
332
+ #~ 'tray_awindow'
333
+ #~ );
334
+
335
+ #window
336
+ my $menuitem_window = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('Window _under Cursor'));
337
+
338
+ # served via interactive XDG portal on Wayland too
339
+ $menuitem_window->set_sensitive(TRUE);
340
+ if ($traytheme->has_icon('preferences-system-windows')) {
341
+ $menuitem_window->set_image(Gtk3::Image->new_from_icon_name('preferences-system-windows', 'menu'));
342
+ } else {
343
+ $menuitem_window->set_image(Gtk3::Image->new_from_pixbuf($lp->load("$shutter_root/share/shutter/resources/icons/sel_window.svg", $shf->icon_size('menu'))));
344
+ }
345
+ $menuitem_window->signal_connect(
346
+ activate => \&Shutter::App::evt_take_screenshot,
347
+ 'tray_window'
348
+ );
349
+
350
+ #window list
351
+ my $menuitem_window_list = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('Select W_indow'));
352
+ $menuitem_window_list->set_sensitive($x11_supported);
353
+ if ($traytheme->has_icon('preferences-system-windows')) {
354
+ $menuitem_window_list->set_image(Gtk3::Image->new_from_icon_name('preferences-system-windows', 'menu'));
355
+ } else {
356
+ $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'))));
357
+ }
358
+ $menuitem_window_list->set_name('windowlist');
359
+ $menuitem_window_list->set_submenu(Shutter::App::fct_ret_window_menu());
360
+
361
+ #section
362
+ # No sections for now: https://github.com/shutter-project/shutter/issues/25
363
+ #my $menuitem_window_sect = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('Se_ction'));
364
+ #if ($traytheme->has_icon('gdm-xnest')) {
365
+ # $menuitem_window_sect->set_image(Gtk3::Image->new_from_icon_name('gdm-xnest', 'menu'));
366
+ #} else {
367
+ # $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'))));
368
+ #}
369
+ #$menuitem_window_sect->signal_connect(
370
+ # activate => \&Shutter::App::evt_take_screenshot,
371
+ # 'tray_section'
372
+ #);
373
+
374
+ #menu
375
+ my $menuitem_window_menu = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('_Menu'));
376
+ $menuitem_window_menu->set_sensitive($x11_supported);
377
+ if ($traytheme->has_icon('alacarte')) {
378
+ $menuitem_window_menu->set_image(Gtk3::Image->new_from_icon_name('alacarte', 'menu'));
379
+ } else {
380
+ $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'))));
381
+ }
382
+ $menuitem_window_menu->signal_connect(
383
+ activate => \&Shutter::App::evt_take_screenshot,
384
+ 'tray_menu'
385
+ );
386
+
387
+ #tooltip
388
+ my $menuitem_window_tooltip = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('_Tooltip'));
389
+ $menuitem_window_tooltip->set_sensitive($x11_supported);
390
+ if ($traytheme->has_icon('help-faq')) {
391
+ $menuitem_window_tooltip->set_image(Gtk3::Image->new_from_icon_name('help-faq', 'menu'));
392
+ } else {
393
+ $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'))));
394
+ }
395
+ $menuitem_window_tooltip->signal_connect(
396
+ activate => \&Shutter::App::evt_take_screenshot,
397
+ 'tray_tooltip'
398
+ );
399
+
400
+ #web
401
+ my $menuitem_web = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('_Web'));
402
+ $menuitem_web->set_sensitive($gnome_web_photo);
403
+ if ($traytheme->has_icon('web-browser')) {
404
+ $menuitem_web->set_image(Gtk3::Image->new_from_icon_name('web-browser', 'menu'));
405
+ } else {
406
+ $menuitem_web->set_image(Gtk3::Image->new_from_pixbuf($lp->load("$shutter_root/share/shutter/resources/icons/web_image.svg", $shf->icon_size('menu'))));
407
+ }
408
+ $menuitem_web->signal_connect(
409
+ activate => \&Shutter::App::evt_take_screenshot,
410
+ 'tray_web'
411
+ );
412
+
413
+ #show main window
414
+ my $menuitem_show_window = Gtk3::MenuItem->new_with_mnemonic($d->get('S_how main window'));
415
+ $menuitem_show_window->signal_connect('activate', sub { ${$is_hidden_ref} = TRUE; Shutter::App::fct_control_main_window('show'); });
416
+ $menuitem_show_window->set_name('show_window');
417
+ $menuitem_show_window->set_sensitive(TRUE);
418
+
419
+ #redo last screenshot
420
+ my $menuitem_redoshot = Gtk3::ImageMenuItem->new_with_mnemonic($d->get('_Redo last screenshot'));
421
+ $menuitem_redoshot->set_image(Gtk3::Image->new_from_stock('gtk-refresh', 'menu'));
422
+ $menuitem_redoshot->signal_connect('activate', \&Shutter::App::evt_take_screenshot, 'redoshot');
423
+ $menuitem_redoshot->set_name('redoshot');
424
+ $menuitem_redoshot->set_sensitive(FALSE);
425
+
426
+ #preferences
427
+ my $menuitem_settings = Gtk3::ImageMenuItem->new_from_stock('gtk-preferences');
428
+ $menuitem_settings->signal_connect("activate", \&Shutter::App::evt_show_settings);
429
+
430
+ #quick profile selector
431
+ my $menuitem_quicks = Gtk3::MenuItem->new_with_mnemonic($d->get('_Quick profile select'));
432
+
433
+ #set name to identify the item later - we use this in really rare cases
434
+ $menuitem_quicks->set_name('quicks');
435
+ $menuitem_quicks->set_sensitive(FALSE);
436
+
437
+ #info
438
+ my $menuitem_info = Gtk3::ImageMenuItem->new_from_stock('gtk-about');
439
+ $menuitem_info->signal_connect("activate", \&Shutter::App::evt_about);
440
+
441
+ #quit
442
+ my $menuitem_quit = Gtk3::ImageMenuItem->new_from_stock('gtk-quit');
443
+ $menuitem_quit->signal_connect("activate", \&Shutter::App::evt_delete_window, 'quit');
444
+
445
+ $menu_tray->append($menuitem_show_window);
446
+ $menu_tray->append(Gtk3::SeparatorMenuItem->new);
447
+ $menu_tray->append($menuitem_redoshot);
448
+ $menu_tray->append(Gtk3::SeparatorMenuItem->new);
449
+ $menu_tray->append($menuitem_select);
450
+
451
+ #~ $menu_tray->append( Gtk3::SeparatorMenuItem->new );
452
+ $menu_tray->append($menuitem_full);
453
+
454
+ #~ $menu_tray->append( Gtk3::SeparatorMenuItem->new );
455
+ #~ $menu_tray->append($menuitem_awindow);
456
+ $menu_tray->append($menuitem_window);
457
+ $menu_tray->append($menuitem_window_list);
458
+
459
+ # No sections for now: https://github.com/shutter-project/shutter/issues/25
460
+ #$menu_tray->append($menuitem_window_sect);
461
+ $menu_tray->append($menuitem_window_menu);
462
+ $menu_tray->append($menuitem_window_tooltip);
463
+
464
+ #~ $menu_tray->append( Gtk3::SeparatorMenuItem->new );
465
+ $menu_tray->append($menuitem_web);
466
+ $menu_tray->append(Gtk3::SeparatorMenuItem->new);
467
+ $menu_tray->append($menuitem_settings);
468
+ $menu_tray->append($menuitem_quicks);
469
+ $menu_tray->append(Gtk3::SeparatorMenuItem->new);
470
+ $menu_tray->append($menuitem_info);
471
+ $menu_tray->append($menuitem_quit);
472
+ $menu_tray->show_all;
473
+
474
+ return $menu_tray;
475
+ }
476
+
477
+ sub program_menu {
478
+ my ($sc, $shf, $sm, $session_screens, $session_start_screen, $menu_programs) = @_;
479
+
480
+ $menu_programs = Gtk3::Menu->new unless defined $menu_programs;
481
+ foreach my $child ($menu_programs->get_children) {
482
+ $child->destroy;
483
+ }
484
+
485
+ #take $key (mime) directly
486
+ my $key = Shutter::App::fct_get_current_file();
487
+
488
+ #FIXME - different mime types
489
+ #have different apps registered
490
+ #we should restrict the offeres apps
491
+ #by comparing the selected
492
+ #
493
+ #currently we just take the last selected file into account
494
+ #
495
+ #search selected files for mime...
496
+ unless ($key) {
497
+ $session_start_screen->{'first_page'}->{'view'}->selected_foreach(
498
+ sub {
499
+ my ($view, $path) = @_;
500
+ my $iter = $session_start_screen->{'first_page'}->{'model'}->get_iter($path);
501
+ if (defined $iter) {
502
+ $key = $session_start_screen->{'first_page'}->{'model'}->get_value($iter, 2);
503
+ }
504
+ });
505
+ }
506
+
507
+ #still no key? => leave sub
508
+ unless ($key) {
509
+ $sm->{_menuitem_reopen}->set_sensitive(FALSE);
510
+ $sm->{_menuitem_large_reopen}->set_sensitive(FALSE);
511
+ return $menu_programs;
512
+ }
513
+
514
+ #no valid hash entry?
515
+ unless (exists $session_screens->{$key}->{'mime_type'}) {
516
+ $sm->{_menuitem_reopen}->set_sensitive(FALSE);
517
+ $sm->{_menuitem_large_reopen}->set_sensitive(FALSE);
518
+ return $menu_programs;
519
+ }
520
+
521
+ #get applications
522
+ my $mime_type = $session_screens->{$key}->{'mime_type'};
523
+
524
+ # apps is a list of GAppInfo
525
+ # https://developer.gnome.org/gio/stable/GAppInfo.html
526
+ my $apps = Glib::IO::AppInfo::get_recommended_for_type($mime_type);
527
+
528
+ # $apps is undefined if Glib::IO::AppInfo::get_recommended_for_type fails
529
+ unless (defined $apps) {
530
+ $sm->{_menuitem_reopen}->set_sensitive(FALSE);
531
+ $sm->{_menuitem_large_reopen}->set_sensitive(FALSE);
532
+ return $menu_programs;
533
+ }
534
+
535
+ #no apps determined!
536
+ unless (scalar @$apps) {
537
+ $sm->{_menuitem_reopen}->set_sensitive(FALSE);
538
+ $sm->{_menuitem_large_reopen}->set_sensitive(FALSE);
539
+ return $menu_programs;
540
+ }
541
+
542
+ #create menu items
543
+ foreach my $app (@$apps) {
544
+
545
+ #ignore Shutter's desktop entry
546
+ next if $app->get_display_name =~ /shutter/i;
547
+
548
+ # $app->{'name'} = $shf->utf8_decode( $app->{'name'} );
549
+
550
+ #FIXME
551
+ #we simply cut the kde* / kde4* substring here
552
+ #is it possible to get the wrong app if there
553
+ #is the kde3 and the kde4 version of an app installed?
554
+ #
555
+ #I think so ;-)
556
+ # $app->{'id'} =~ s/^(kde4|kde)-//g;
557
+
558
+ my $program_item = Gtk3::ImageMenuItem->new_with_label($app->get_display_name);
559
+ $program_item->set('always_show_image' => TRUE);
560
+ $menu_programs->append($program_item);
561
+
562
+ my $icon = $app->get_icon;
563
+ if ($icon && $program_item) {
564
+ my $icon_pixbuf = undef;
565
+ my ($iw, $ih) = $shf->icon_size('menu');
566
+ eval {
567
+ my $icon_info = $sc->get_theme->choose_icon($icon->get_names, $ih, []);
568
+ $icon_pixbuf = $icon_info->load_icon if $icon_info;
569
+ };
570
+ if ($@) {
571
+ print "\nWARNING: Could not load icon for ", $app->get_display_name, ": $@\n";
572
+ $icon_pixbuf = undef;
573
+ }
574
+ if ($icon_pixbuf) {
575
+ $program_item->set_image(Gtk3::Image->new_from_pixbuf($icon_pixbuf));
576
+ }
577
+ }
578
+
579
+ #connect to signal
580
+ if ($program_item) {
581
+ $program_item->signal_connect(
582
+ 'activate' => sub {
583
+ Shutter::App::fct_open_with_program($app, $app->get_display_name);
584
+ });
585
+ }
586
+ }
587
+
588
+ #menu does not contain any item
589
+ unless ($menu_programs->get_children) {
590
+ $sm->{_menuitem_reopen}->set_sensitive(FALSE);
591
+ $sm->{_menuitem_large_reopen}->set_sensitive(FALSE);
592
+ }
593
+
594
+ $menu_programs->show_all;
595
+ return $menu_programs;
596
+ }
597
+
598
+ sub web_menu {
599
+ my ($d, $settings_xml) = @_;
600
+
601
+ my $menu_web = Gtk3::Menu->new;
602
+
603
+ my $timeout0 = Gtk3::RadioMenuItem->new_with_label(undef, $d->get("Wait indefinitely"));
604
+ my $timeout1 = Gtk3::RadioMenuItem->new_with_label($timeout0, sprintf($d->nget("Wait max %d second", "Wait max %d seconds", 10), 10));
605
+ my $timeout2 = Gtk3::RadioMenuItem->new_with_label($timeout0, sprintf($d->nget("Wait max %d second", "Wait max %d seconds", 10), 30));
606
+ my $timeout3 = Gtk3::RadioMenuItem->new_with_label($timeout0, sprintf($d->nget("Wait max %d minute", "Wait max %d minutes", 1), 1));
607
+ my $timeout4 = Gtk3::RadioMenuItem->new_with_label($timeout0, sprintf($d->nget("Wait max %d minute", "Wait max %d minutes", 2), 2));
608
+
609
+ $timeout0->set_name("timeout0");
610
+ $timeout1->set_name("timeout10");
611
+ $timeout2->set_name("timeout30");
612
+ $timeout3->set_name("timeout60");
613
+ $timeout4->set_name("timeout120");
614
+
615
+ $timeout0->set_tooltip_text($d->get("Shutter will wait indefinitely for the screenshot to capture"));
616
+ $timeout1->set_tooltip_text(
617
+ sprintf(
618
+ $d->nget(
619
+ "Shutter will wait up to %d second for the screenshot to capture before aborting the process if it's taking too long",
620
+ "Shutter will wait up to %d seconds for the screenshot to capture before aborting the process if it's taking too long",
621
+ 10
622
+ ),
623
+ 10
624
+ ));
625
+ $timeout2->set_tooltip_text(
626
+ sprintf(
627
+ $d->nget(
628
+ "Shutter will wait up to %d second for the screenshot to capture before aborting the process if it's taking too long",
629
+ "Shutter will wait up to %d seconds for the screenshot to capture before aborting the process if it's taking too long",
630
+ 30
631
+ ),
632
+ 30
633
+ ));
634
+ $timeout3->set_tooltip_text(
635
+ sprintf(
636
+ $d->nget(
637
+ "Shutter will wait up to %d minute for the screenshot to capture before aborting the process if it's taking too long",
638
+ "Shutter will wait up to %d minutes for the screenshot to capture before aborting the process if it's taking too long",
639
+ 1
640
+ ),
641
+ 1
642
+ ));
643
+ $timeout4->set_tooltip_text(
644
+ sprintf(
645
+ $d->nget(
646
+ "Shutter will wait up to %d minute for the screenshot to capture before aborting the process if it's taking too long",
647
+ "Shutter will wait up to %d minutes for the screenshot to capture before aborting the process if it's taking too long",
648
+ 2
649
+ ),
650
+ 2
651
+ ));
652
+
653
+ $timeout2->set_active(TRUE);
654
+ $menu_web->append($timeout0);
655
+ $menu_web->append($timeout1);
656
+ $menu_web->append($timeout2);
657
+ $menu_web->append($timeout3);
658
+ $menu_web->append($timeout4);
659
+
660
+ if (defined $settings_xml->{'general'}->{'web_timeout'}) {
661
+
662
+ #determining timeout
663
+ my @timeouts = $menu_web->get_children;
664
+ my $timeout = undef;
665
+ foreach my $to (@timeouts) {
666
+ $timeout = $to->get_name;
667
+ $timeout =~ /([0-9]+)/;
668
+ $timeout = $1;
669
+ if ($settings_xml->{'general'}->{'web_timeout'} == $timeout) {
670
+ $to->set_active(TRUE);
671
+ }
672
+ }
673
+ }
674
+ $menu_web->show_all;
675
+ return $menu_web;
676
+ }
677
+
678
+ sub profile_menu {
679
+ my $current_profile_indx_ref = shift;
680
+ my $combobox_settings_profiles = shift;
681
+ my $current_profiles_ref = shift;
682
+ my $menu_profile = shift;
683
+
684
+ $menu_profile = Gtk3::Menu->new unless defined $menu_profile;
685
+ foreach my $child ($menu_profile->get_children) {
686
+ $child->destroy;
687
+ }
688
+
689
+ my $group = undef;
690
+ my $counter = 0;
691
+ foreach my $profile (@{$current_profiles_ref}) {
692
+ my $profile_item = Gtk3::RadioMenuItem->new_with_label($group, $profile);
693
+ $profile_item->set_active(TRUE)
694
+ if $profile eq $combobox_settings_profiles->get_active_text;
695
+ $profile_item->signal_connect(
696
+ 'toggled' => sub {
697
+ my $widget = shift;
698
+ return TRUE unless $widget->get_active;
699
+
700
+ for (my $i = 0 ; $i < scalar @{$current_profiles_ref} ; $i++) {
701
+ $combobox_settings_profiles->set_active($i);
702
+ ${$current_profile_indx_ref} = $i;
703
+ if ($profile eq $combobox_settings_profiles->get_active_text) {
704
+ Shutter::App::evt_apply_profile($widget, $combobox_settings_profiles, $current_profiles_ref);
705
+ last;
706
+ }
707
+ }
708
+ });
709
+ $group = $profile_item unless $group;
710
+ $menu_profile->append($profile_item);
711
+ $counter++;
712
+ }
713
+
714
+ $menu_profile->show_all;
715
+ return $menu_profile;
716
+ }
717
+
718
+ 1;
t/Shutter/App/16_menus.t ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/perl
2
+ use 5.010;
3
+ use strict;
4
+ use warnings;
5
+
6
+ use Gtk3; # to escape warnings "Too late to run INIT block"
7
+
8
+ use Test::More;
9
+ use Glib qw/ TRUE FALSE /;
10
+
11
+ plan skip_all => "no display available" unless Gtk3::init_check();
12
+
13
+ require_ok("Shutter::App::ContextMenus");
14
+ can_ok("Shutter::App::ContextMenus", qw/ workspace_menu window_menu tray_menu program_menu web_menu profile_menu /);
15
+
16
+ #--------------------------------------
17
+ # minimal stand-ins for Shutter's objects
18
+ #--------------------------------------
19
+ sub Local::Gettext::new { return bless {}, shift }
20
+ sub Local::Gettext::get { return $_[1] }
21
+ sub Local::Gettext::nget { my ($self, $one, $many, $n) = @_; return $n == 1 ? $one : $many }
22
+
23
+ sub Local::Common::new { return bless {}, shift }
24
+ sub Local::Common::get_theme { return Gtk3::IconTheme::get_default() }
25
+ sub Local::Common::get_debug { return 0 }
26
+
27
+ sub Local::HelperFunctions::new { return bless {}, shift }
28
+ sub Local::HelperFunctions::icon_size { return (16, 16) }
29
+
30
+ sub Local::Pixbuf::new { return bless {loaded => []}, shift }
31
+
32
+ sub Local::Pixbuf::load {
33
+ my ($self, $file) = @_;
34
+ push @{$self->{loaded}}, $file;
35
+ return Gtk3::Gdk::Pixbuf->new('rgb', TRUE, 8, 16, 16);
36
+ }
37
+
38
+ sub Local::Sensitive::new { return bless {sensitive => TRUE}, shift }
39
+ sub Local::Sensitive::set_sensitive { $_[0]->{sensitive} = $_[1]; return }
40
+
41
+ sub Local::View::new { return bless {}, shift }
42
+ sub Local::View::selected_foreach { return }
43
+
44
+ #calls the module makes back into bin/shutter
45
+ my @calls;
46
+ sub Shutter::App::fct_ret_window_menu { push @calls, ['fct_ret_window_menu']; return Gtk3::Menu->new }
47
+ sub Shutter::App::fct_control_main_window { push @calls, ['fct_control_main_window', @_]; return }
48
+ sub Shutter::App::fct_get_current_file { return }
49
+ sub Shutter::App::evt_apply_profile { push @calls, ['evt_apply_profile', @_]; return }
50
+
51
+ my $d = Local::Gettext->new;
52
+ my $sc = Local::Common->new;
53
+ my $shf = Local::HelperFunctions->new;
54
+
55
+ sub names_of {
56
+ return map { $_->get_name } $_[0]->get_children;
57
+ }
58
+
59
+ subtest "web_menu" => sub {
60
+ my $menu = Shutter::App::ContextMenus::web_menu($d, {});
61
+ isa_ok($menu, "Gtk3::Menu");
62
+ my @items = $menu->get_children;
63
+ is_deeply([names_of($menu)], [qw/ timeout0 timeout10 timeout30 timeout60 timeout120 /], "five timeout items");
64
+ is($items[0]->get_label, "Wait indefinitely", "label of first item");
65
+ is($items[3]->get_label, "Wait max 1 minute", "singular form used");
66
+ is($items[4]->get_label, "Wait max 2 minutes", "plural form used");
67
+ ok($items[2]->get_active, "30 seconds is the default");
68
+
69
+ $menu = Shutter::App::ContextMenus::web_menu($d, {general => {web_timeout => 120}});
70
+ @items = $menu->get_children;
71
+ ok($items[4]->get_active, "timeout from settings is selected");
72
+ ok(!$items[2]->get_active, "default no longer selected");
73
+ };
74
+
75
+ subtest "profile_menu" => sub {
76
+ my $combo = Gtk3::ComboBoxText->new;
77
+ my @profiles = qw/ alpha beta gamma /;
78
+ $combo->append_text($_) for @profiles;
79
+ $combo->set_active(1);
80
+ my $indx = 1;
81
+
82
+ my $menu = Shutter::App::ContextMenus::profile_menu(\$indx, $combo, \@profiles);
83
+ isa_ok($menu, "Gtk3::Menu");
84
+ my @items = $menu->get_children;
85
+ is_deeply([map { $_->get_label } @items], \@profiles, "one item per profile");
86
+ ok($items[1]->get_active, "current profile is active");
87
+
88
+ @calls = ();
89
+ $items[2]->set_active(TRUE);
90
+ is($indx, 2, "current profile index updated through reference");
91
+ is($combo->get_active, 2, "combobox switched");
92
+ is(scalar @calls, 1, "evt_apply_profile called once");
93
+ is($calls[0][0], 'evt_apply_profile', "evt_apply_profile called");
94
+ is($calls[0][2], $combo, "combobox passed on");
95
+ is($calls[0][3], \@profiles, "profiles passed on");
96
+
97
+ my $same = Shutter::App::ContextMenus::profile_menu(\$indx, $combo, [qw/ one two /], $menu);
98
+ is($same, $menu, "existing menu is reused");
99
+ is_deeply([map { $_->get_label } $same->get_children], [qw/ one two /], "old items replaced");
100
+ };
101
+
102
+ subtest "window_menu without wnck screen" => sub {
103
+ my $menu = Shutter::App::ContextMenus::window_menu($sc, $d, Local::Pixbuf->new, $shf, "/nonexistent", undef);
104
+ isa_ok($menu, "Gtk3::Menu");
105
+ is(scalar(my @c = $menu->get_children), 0, "empty menu");
106
+ };
107
+
108
+ subtest "workspace_menu without X11 support" => sub {
109
+ my $cma = undef;
110
+ my $menu = Shutter::App::ContextMenus::workspace_menu($sc, $d, {}, FALSE, \$cma, TRUE);
111
+ isa_ok($menu, "Gtk3::Menu");
112
+ my $n_mons = Gtk3::Gdk::Screen::get_default->get_n_monitors;
113
+ is(scalar(my @c = $menu->get_children), $n_mons > 1 ? $n_mons : 0, "one item per monitor if more than one");
114
+ ok(!defined $cma, "current monitor item untouched");
115
+ };
116
+
117
+ subtest "program_menu without a selected file" => sub {
118
+ my $sm = {_menuitem_reopen => Local::Sensitive->new, _menuitem_large_reopen => Local::Sensitive->new};
119
+ my %session_start_screen = (first_page => {view => Local::View->new});
120
+ my $existing = Gtk3::Menu->new;
121
+ $existing->append(Gtk3::MenuItem->new_with_label("stale"));
122
+
123
+ my $menu = Shutter::App::ContextMenus::program_menu($sc, $shf, $sm, {}, \%session_start_screen, $existing);
124
+ is($menu, $existing, "existing menu is reused");
125
+ is(scalar(my @c = $menu->get_children), 0, "stale items removed");
126
+ is($sm->{_menuitem_reopen}->{sensitive}, FALSE, "reopen disabled");
127
+ is($sm->{_menuitem_large_reopen}->{sensitive}, FALSE, "large reopen disabled");
128
+ };
129
+
130
+ subtest "tray_menu" => sub {
131
+ my $lp = Local::Pixbuf->new;
132
+ my $is_hidden = FALSE;
133
+ @calls = ();
134
+
135
+ my $menu = Shutter::App::ContextMenus::tray_menu($sc, $d, $lp, $shf, "/root", FALSE, TRUE, \$is_hidden);
136
+ isa_ok($menu, "Gtk3::Menu");
137
+ my %by_name = map { $_->get_name => $_ } $menu->get_children;
138
+
139
+ ok(exists $by_name{$_}, "has item '$_'") for qw/ show_window redoshot windowlist quicks /;
140
+ ok(!$by_name{redoshot}->get_sensitive, "redo is disabled initially");
141
+ ok(!$by_name{quicks}->get_sensitive, "quick profile select is disabled initially");
142
+ ok(!$by_name{windowlist}->get_sensitive, "window list follows x11 support");
143
+ isa_ok($by_name{windowlist}->get_submenu, "Gtk3::Menu", "window list submenu");
144
+ is_deeply($calls[0], ['fct_ret_window_menu'], "window list built via fct_ret_window_menu");
145
+ ok((grep { m{^/root/share/shutter/resources/icons/} } @{$lp->{loaded}}) || !@{$lp->{loaded}}, "fallback icons loaded from shutter root");
146
+
147
+ @calls = ();
148
+ $by_name{show_window}->activate;
149
+ is($is_hidden, TRUE, "is_hidden set through reference");
150
+ is_deeply(\@calls, [['fct_control_main_window', 'show']], "main window shown");
151
+ };
152
+
153
+ done_testing();