Xfce Forum

Sub domains
 

You are not logged in.

#1 2011-08-21 18:02:12

RPG
Member
Registered: 2011-08-21
Posts: 8

Closing windows with middle mouse button

I often open multiple windows, but do not use the grouping of windows, because it's inconvenient for me. To close multiple windows, I have to right click on each window and look out there "Close".
Many browsers (firefox, chrome) use the middle mouse button for closing tabs. It is very convenient and can be used to close the windows. However, xfce does not provide this features and I decided to add it.

I found in tasklist-widget.c this part of code:

static gboolean
xfce_tasklist_button_button_press_event (GtkWidget         *button,
                                         GdkEventButton    *event,
                                         XfceTasklistChild *child)
{
  GtkWidget *menu, *panel_plugin;

  panel_return_val_if_fail (XFCE_IS_TASKLIST (child->tasklist), FALSE);
  panel_return_val_if_fail (child->type != CHILD_TYPE_GROUP, FALSE);

  if (event->type != GDK_BUTTON_PRESS
      || xfce_taskbar_is_locked (child->tasklist))
    return FALSE;

  /* send the event to the panel plugin if control is pressed */
  if (PANEL_HAS_FLAG (event->state, GDK_CONTROL_MASK))
    {
      /* send the event to the panel plugin */
      panel_plugin = xfce_tasklist_get_panel_plugin (child->tasklist);
      if (G_LIKELY (panel_plugin != NULL))
        gtk_widget_event (panel_plugin, (GdkEvent *) event);

      return TRUE;
    }

  if (event->button == 1)
    {
      xfce_tasklist_button_activate (child, event->time);

      return TRUE;
    }
  else if (event->button == 3)
    {
      menu = wnck_action_menu_new (child->window);
      g_signal_connect (G_OBJECT (menu), "selection-done",
          G_CALLBACK (gtk_widget_destroy), NULL);

      gtk_menu_attach_to_widget (GTK_MENU (menu), button, NULL);
      gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
                      xfce_panel_plugin_position_menu,
                      xfce_tasklist_get_panel_plugin (child->tasklist),
                      event->button,
                      event->time);

      return TRUE;
    }

  return FALSE;
}

This part handles clicking on the taskbar. This code i replaced on this:

static gboolean
xfce_tasklist_button_button_press_event (GtkWidget         *button,
                                         GdkEventButton    *event,
                                         XfceTasklistChild *child)
{
  GtkWidget *menu, *panel_plugin;

  panel_return_val_if_fail (XFCE_IS_TASKLIST (child->tasklist), FALSE);
  panel_return_val_if_fail (child->type != CHILD_TYPE_GROUP, FALSE);

  if (event->type != GDK_BUTTON_PRESS
      || xfce_taskbar_is_locked (child->tasklist))
    return FALSE;

  /* send the event to the panel plugin if control is pressed */
  if (PANEL_HAS_FLAG (event->state, GDK_CONTROL_MASK))
    {
      /* send the event to the panel plugin */
      panel_plugin = xfce_tasklist_get_panel_plugin (child->tasklist);
      if (G_LIKELY (panel_plugin != NULL))
        gtk_widget_event (panel_plugin, (GdkEvent *) event);

      return TRUE;
    }

  if (event->button == 1)
    {
      xfce_tasklist_button_activate (child, event->time);

      return TRUE;
    }
  else if (event->button == 2)
  {
    wnck_window_close (child->window, gtk_get_current_event_time ());
    return TRUE;
  }
  else if (event->button == 3)
    {
      menu = wnck_action_menu_new (child->window);
      g_signal_connect (G_OBJECT (menu), "selection-done",
          G_CALLBACK (gtk_widget_destroy), NULL);

      gtk_menu_attach_to_widget (GTK_MENU (menu), button, NULL);
      gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
                      xfce_panel_plugin_position_menu,
                      xfce_tasklist_get_panel_plugin (child->tasklist),
                      event->button,
                      event->time);

      return TRUE;
    }

  return FALSE;
}

re-compile tasklist-plugin and enjoy:)

I hope to see this feature in next XFCE releases.

Offline

#2 2012-04-27 10:47:11

putti
Member
Registered: 2012-04-27
Posts: 1

Re: Closing windows with middle mouse button

Thank you! smile

Offline

#3 2012-05-02 03:37:19

soleen
Member
Registered: 2006-08-02
Posts: 5

Re: Closing windows with middle mouse button

RPG thanks! Please file a bug, and post the bug number here. This is a small feature that should be implemented!

Offline

#4 2012-06-18 08:32:28

Wakope
Member
Registered: 2012-06-18
Posts: 1

Re: Closing windows with middle mouse button

Offline

#5 2012-07-05 22:51:10

Ancurio
Member
Registered: 2011-02-08
Posts: 15

Re: Closing windows with middle mouse button

Thank you so very much!
I have been thinking the exact same thing for the last couple weeks,
but never got around opening a feature request.

Offline

#6 2012-12-25 15:41:15

RPG
Member
Registered: 2011-08-21
Posts: 8

Re: Closing windows with middle mouse button

I'm very glad to see usefull and complete patch about it here: https://bugzilla.xfce.org/show_bug.cgi?id=8096

Hope this feature will be included in new releases.

Offline

#7 2015-09-22 12:40:56

Sharky
Member
Registered: 2014-08-16
Posts: 51

Re: Closing windows with middle mouse button

Spamming this at the end of all the threads about this, since anyone looking for this only cares about this info (now it's been patched - thanks guys!):

Right click on Panel > Panel preferences > Items > Window Buttons > Settings > Behaviour : Middle Click Action

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.013 seconds, 8 queries executed - Memory usage: 546.38 KiB (Peak: 547.23 KiB) ]