1998-10-30 03:47:54 +03:00
|
|
|
/* Desktop management for the Midnight Commander
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998 The Free Software Foundation
|
1998-02-27 08:10:44 +03:00
|
|
|
*
|
1998-10-30 03:47:54 +03:00
|
|
|
* Authors: Federico Mena <federico@nuclecu.unam.mx>
|
|
|
|
* Miguel de Icaza <miguel@nuclecu.unam.mx>
|
1998-02-27 08:10:44 +03:00
|
|
|
*/
|
1998-11-07 04:19:53 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* TO-DO list for the desktop;
|
|
|
|
*
|
|
|
|
* - Put an InputOnly window over icons to be able to select them even if the user clicks on
|
|
|
|
* the transparent area.
|
|
|
|
*
|
|
|
|
* - DnD from file windows to icons.
|
|
|
|
*
|
|
|
|
* - DnD from icons to desktop (move icon).
|
|
|
|
*
|
|
|
|
* - DnD from icons to windows.
|
|
|
|
*
|
|
|
|
* - DnD from icons to icons (file->directory or file->executable).
|
|
|
|
*
|
|
|
|
* - Popup menus for icons.
|
|
|
|
*
|
|
|
|
* - Select icons with rubberband on the root window.
|
|
|
|
*
|
|
|
|
*/
|
1998-12-09 20:23:38 +03:00
|
|
|
|
1998-10-30 03:47:54 +03:00
|
|
|
#include <config.h>
|
1998-11-02 10:26:19 +03:00
|
|
|
#include "fs.h"
|
1998-12-03 02:37:27 +03:00
|
|
|
#include <gdk/gdkx.h>
|
|
|
|
#include <gtk/gtkinvisible.h>
|
1998-10-30 03:47:54 +03:00
|
|
|
#include <gnome.h>
|
1998-10-31 02:22:35 +03:00
|
|
|
#include "dialog.h"
|
1998-12-07 05:36:47 +03:00
|
|
|
#define DIR_H_INCLUDE_HANDLE_DIRENT /* bleah */
|
|
|
|
#include "dir.h"
|
1998-12-30 05:51:01 +03:00
|
|
|
#include "file.h"
|
1998-10-30 03:47:54 +03:00
|
|
|
#include "gdesktop.h"
|
1998-10-31 02:22:35 +03:00
|
|
|
#include "gdesktop-icon.h"
|
1998-12-09 20:23:38 +03:00
|
|
|
#include "gicon.h"
|
1998-12-07 05:36:47 +03:00
|
|
|
#include "gmain.h"
|
1998-10-30 20:08:03 +03:00
|
|
|
#include "gmetadata.h"
|
1998-12-03 02:37:27 +03:00
|
|
|
#include "gdnd.h"
|
1998-11-25 06:29:23 +03:00
|
|
|
#include "gpopup.h"
|
1998-10-30 03:47:54 +03:00
|
|
|
#include "../vfs/vfs.h"
|
|
|
|
|
|
|
|
|
1998-11-07 04:19:53 +03:00
|
|
|
/* Name of the user's desktop directory (i.e. ~/desktop) */
|
1998-10-30 03:47:54 +03:00
|
|
|
#define DESKTOP_DIR_NAME "desktop"
|
|
|
|
|
|
|
|
|
1998-11-03 04:32:38 +03:00
|
|
|
struct layout_slot {
|
1998-12-11 11:58:26 +03:00
|
|
|
int num_icons; /* Number of icons in this slot */
|
|
|
|
GList *icons; /* The list of icons in this slot */
|
1998-11-03 04:32:38 +03:00
|
|
|
};
|
|
|
|
|
1998-10-30 03:47:54 +03:00
|
|
|
|
1998-10-30 20:08:03 +03:00
|
|
|
/* Configuration options for the desktop */
|
|
|
|
|
1998-10-30 03:47:54 +03:00
|
|
|
int desktop_use_shaped_icons = TRUE;
|
1998-10-30 20:08:03 +03:00
|
|
|
int desktop_auto_placement = FALSE;
|
1998-12-08 04:31:17 +03:00
|
|
|
int desktop_snap_icons = FALSE;
|
1998-10-30 03:47:54 +03:00
|
|
|
|
|
|
|
/* The computed name of the user's desktop directory */
|
|
|
|
static char *desktop_directory;
|
|
|
|
|
1998-10-31 02:22:35 +03:00
|
|
|
/* Layout information: number of rows/columns for the layout slots, and the array of slots. Each
|
|
|
|
* slot is an integer that specifies the number of icons that belong to that slot.
|
|
|
|
*/
|
1998-12-07 18:47:00 +03:00
|
|
|
static int layout_screen_width;
|
|
|
|
static int layout_screen_height;
|
1998-10-30 03:47:54 +03:00
|
|
|
static int layout_cols;
|
|
|
|
static int layout_rows;
|
1998-11-03 04:32:38 +03:00
|
|
|
static struct layout_slot *layout_slots;
|
1998-10-30 03:47:54 +03:00
|
|
|
|
1998-11-03 19:29:47 +03:00
|
|
|
#define l_slots(u, v) (layout_slots[(u) * layout_rows + (v)])
|
1998-10-31 02:22:35 +03:00
|
|
|
|
1998-11-03 04:32:38 +03:00
|
|
|
/* The last icon to be selected */
|
1998-12-31 04:43:11 +03:00
|
|
|
static DesktopIconInfo *last_selected_icon;
|
1998-11-03 04:32:38 +03:00
|
|
|
|
1998-12-08 04:31:17 +03:00
|
|
|
/* Drag and drop sources and targets */
|
1998-12-05 04:01:13 +03:00
|
|
|
|
1998-12-08 04:31:17 +03:00
|
|
|
static GtkTargetEntry dnd_icon_sources[] = {
|
1998-12-11 05:05:19 +03:00
|
|
|
{ "application/x-mc-desktop-icon", 0, TARGET_MC_DESKTOP_ICON },
|
1998-12-05 04:01:13 +03:00
|
|
|
{ "text/uri-list", 0, TARGET_URI_LIST },
|
1998-12-11 21:12:21 +03:00
|
|
|
{ "text/plain", 0, TARGET_TEXT_PLAIN },
|
|
|
|
{ "_NETSCAPE_URL", 0, TARGET_URL }
|
1998-12-05 04:01:13 +03:00
|
|
|
};
|
|
|
|
|
1998-12-08 04:31:17 +03:00
|
|
|
static GtkTargetEntry dnd_icon_targets[] = {
|
|
|
|
{ "text/uri-list", 0, TARGET_URI_LIST }
|
|
|
|
};
|
|
|
|
|
|
|
|
static GtkTargetEntry dnd_desktop_targets[] = {
|
1998-12-11 05:05:19 +03:00
|
|
|
{ "application/x-mc-desktop-icon", 0, TARGET_MC_DESKTOP_ICON },
|
1998-12-03 02:37:27 +03:00
|
|
|
{ "text/uri-list", 0, TARGET_URI_LIST }
|
|
|
|
};
|
|
|
|
|
1998-12-08 04:31:17 +03:00
|
|
|
static int dnd_icon_nsources = sizeof (dnd_icon_sources) / sizeof (dnd_icon_sources[0]);
|
|
|
|
static int dnd_icon_ntargets = sizeof (dnd_icon_targets) / sizeof (dnd_icon_targets[0]);
|
|
|
|
static int dnd_desktop_ntargets = sizeof (dnd_desktop_targets) / sizeof (dnd_desktop_targets[0]);
|
1998-12-03 02:37:27 +03:00
|
|
|
|
1998-12-04 05:08:06 +03:00
|
|
|
/* Proxy window for DnD on the root window */
|
1998-12-03 02:37:27 +03:00
|
|
|
static GtkWidget *dnd_proxy_window;
|
|
|
|
|
1998-12-08 00:07:27 +03:00
|
|
|
/* Offsets for the DnD cursor hotspot */
|
|
|
|
static int dnd_press_x, dnd_press_y;
|
|
|
|
|
1998-12-11 05:05:19 +03:00
|
|
|
/* Whether a call to select_icon() is pending because the initial click on an
|
|
|
|
* icon had the GDK_CONTROL_MASK in it. */
|
|
|
|
static int dnd_select_icon_pending;
|
|
|
|
|
|
|
|
/* Proxy window for clicks on the root window */
|
|
|
|
static GdkWindow *click_proxy_gdk_window;
|
|
|
|
static GtkWidget *click_proxy_invisible;
|
|
|
|
|
1998-12-11 15:59:47 +03:00
|
|
|
/* GC for drawing the rubberband rectangle */
|
|
|
|
static GdkGC *click_gc;
|
|
|
|
|
|
|
|
/* Starting click position and event state for rubberbanding on the desktop */
|
|
|
|
static int click_start_x;
|
|
|
|
static int click_start_y;
|
|
|
|
static int click_start_state;
|
|
|
|
|
|
|
|
/* Current mouse position for rubberbanding on the desktop */
|
|
|
|
static int click_current_x;
|
|
|
|
static int click_current_y;
|
|
|
|
|
|
|
|
static int click_dragging;
|
|
|
|
|
1998-10-31 02:22:35 +03:00
|
|
|
|
1998-12-31 04:43:11 +03:00
|
|
|
static DesktopIconInfo *desktop_icon_info_new (char *filename, int auto_pos, int xpos, int ypos);
|
1998-12-07 05:36:47 +03:00
|
|
|
|
|
|
|
|
1998-10-31 02:22:35 +03:00
|
|
|
/* Looks for a free slot in the layout_slots array and returns the coordinates that coorespond to
|
|
|
|
* it. "Free" means it either has zero icons in it, or it has the minimum number of icons of all
|
|
|
|
* the slots.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
get_icon_auto_pos (int *x, int *y)
|
|
|
|
{
|
|
|
|
int min, min_x, min_y;
|
|
|
|
int u, v;
|
|
|
|
int val;
|
|
|
|
|
1998-11-03 04:32:38 +03:00
|
|
|
min = l_slots (0, 0).num_icons;
|
1998-10-31 02:22:35 +03:00
|
|
|
min_x = min_y = 0;
|
|
|
|
|
|
|
|
for (u = 0; u < layout_cols; u++)
|
|
|
|
for (v = 0; v < layout_rows; v++) {
|
1998-11-03 04:32:38 +03:00
|
|
|
val = l_slots (u, v).num_icons;
|
1998-10-31 02:22:35 +03:00
|
|
|
|
|
|
|
if (val == 0) {
|
|
|
|
/* Optimization: if it is zero, return immediately */
|
|
|
|
|
|
|
|
*x = u * DESKTOP_SNAP_X;
|
|
|
|
*y = v * DESKTOP_SNAP_Y;
|
|
|
|
return;
|
|
|
|
} else if (val < min) {
|
|
|
|
min = val;
|
|
|
|
min_x = u;
|
|
|
|
min_y = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*x = min_x * DESKTOP_SNAP_X;
|
|
|
|
*y = min_y * DESKTOP_SNAP_Y;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Snaps the specified position to the icon grid. It looks for the closest free spot on the grid,
|
|
|
|
* or the closest one that has the least number of icons in it.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
get_icon_snap_pos (int *x, int *y)
|
|
|
|
{
|
|
|
|
int min, min_x, min_y;
|
|
|
|
int min_dist;
|
|
|
|
int u, v;
|
|
|
|
int val, dist;
|
|
|
|
int dx, dy;
|
|
|
|
|
1998-11-03 04:32:38 +03:00
|
|
|
min = l_slots (0, 0).num_icons;
|
1998-10-31 02:22:35 +03:00
|
|
|
min_x = min_y = 0;
|
|
|
|
min_dist = INT_MAX;
|
|
|
|
|
|
|
|
for (u = 0; u < layout_cols; u++)
|
|
|
|
for (v = 0; v < layout_rows; v++) {
|
1998-11-03 04:32:38 +03:00
|
|
|
val = l_slots (u, v).num_icons;
|
1998-10-31 02:22:35 +03:00
|
|
|
|
1998-12-05 04:01:13 +03:00
|
|
|
dx = *x - u * DESKTOP_SNAP_X;
|
|
|
|
dy = *y - v * DESKTOP_SNAP_Y;
|
1998-10-31 02:22:35 +03:00
|
|
|
dist = dx * dx + dy * dy;
|
|
|
|
|
1998-11-03 19:29:47 +03:00
|
|
|
if ((val == min && dist < min_dist) || (val < min)) {
|
1998-12-05 04:01:13 +03:00
|
|
|
min = val;
|
1998-10-31 02:22:35 +03:00
|
|
|
min_dist = dist;
|
|
|
|
min_x = u;
|
|
|
|
min_y = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*x = min_x * DESKTOP_SNAP_X;
|
|
|
|
*y = min_y * DESKTOP_SNAP_Y;
|
|
|
|
}
|
1998-10-30 03:47:54 +03:00
|
|
|
|
1998-11-03 04:32:38 +03:00
|
|
|
/* Removes an icon from the slot it is in, if any */
|
|
|
|
static void
|
1998-12-31 04:43:11 +03:00
|
|
|
remove_from_slot (DesktopIconInfo *dii)
|
1998-11-03 04:32:38 +03:00
|
|
|
{
|
|
|
|
if (dii->slot == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_assert (layout_slots[dii->slot].num_icons >= 1);
|
|
|
|
g_assert (layout_slots[dii->slot].icons != NULL);
|
|
|
|
|
|
|
|
layout_slots[dii->slot].num_icons--;
|
|
|
|
layout_slots[dii->slot].icons = g_list_remove (layout_slots[dii->slot].icons, dii);
|
|
|
|
}
|
|
|
|
|
1998-12-17 07:51:24 +03:00
|
|
|
/*
|
|
|
|
* Places a desktop icon. If auto_pos is true, then the function will
|
|
|
|
* look for a place to position the icon automatically, else it will
|
|
|
|
* use the specified coordinates, snapped to the grid if the global
|
|
|
|
* desktop_snap_icons flag is set.
|
1998-10-30 20:08:03 +03:00
|
|
|
*/
|
|
|
|
static void
|
1998-12-31 04:43:11 +03:00
|
|
|
desktop_icon_info_place (DesktopIconInfo *dii, int auto_pos, int xpos, int ypos)
|
1998-10-30 20:08:03 +03:00
|
|
|
{
|
1998-10-31 02:22:35 +03:00
|
|
|
int u, v;
|
1998-11-24 06:58:05 +03:00
|
|
|
char *filename;
|
1998-10-31 02:22:35 +03:00
|
|
|
|
1998-12-05 04:01:13 +03:00
|
|
|
if (auto_pos) {
|
|
|
|
if (desktop_auto_placement)
|
|
|
|
get_icon_auto_pos (&xpos, &ypos);
|
|
|
|
else if (desktop_snap_icons)
|
|
|
|
get_icon_snap_pos (&xpos, &ypos);
|
|
|
|
}
|
1998-10-31 02:22:35 +03:00
|
|
|
|
1998-12-08 00:07:27 +03:00
|
|
|
if (xpos < 0)
|
|
|
|
xpos = 0;
|
|
|
|
else if (xpos > layout_screen_width)
|
1998-12-07 18:47:00 +03:00
|
|
|
xpos = layout_screen_width - DESKTOP_SNAP_X;
|
|
|
|
|
1998-12-08 00:07:27 +03:00
|
|
|
if (ypos < 0)
|
|
|
|
ypos = 0;
|
|
|
|
else if (ypos > layout_screen_height)
|
1998-12-07 18:47:00 +03:00
|
|
|
ypos = layout_screen_height - DESKTOP_SNAP_Y;
|
|
|
|
|
1998-10-31 02:22:35 +03:00
|
|
|
/* Increase the number of icons in the corresponding slot */
|
|
|
|
|
1998-11-03 04:32:38 +03:00
|
|
|
remove_from_slot (dii);
|
|
|
|
|
1998-10-31 02:22:35 +03:00
|
|
|
u = xpos / DESKTOP_SNAP_X;
|
|
|
|
v = ypos / DESKTOP_SNAP_Y;
|
1998-11-03 04:32:38 +03:00
|
|
|
|
|
|
|
dii->slot = u * layout_rows + v;
|
|
|
|
layout_slots[dii->slot].num_icons++;
|
|
|
|
layout_slots[dii->slot].icons = g_list_append (layout_slots[dii->slot].icons, dii);
|
1998-10-31 02:22:35 +03:00
|
|
|
|
|
|
|
/* Move the icon */
|
|
|
|
|
|
|
|
dii->x = xpos;
|
|
|
|
dii->y = ypos;
|
|
|
|
gtk_widget_set_uposition (dii->dicon, xpos, ypos);
|
1998-11-24 06:58:05 +03:00
|
|
|
|
|
|
|
/* Save the information */
|
|
|
|
|
|
|
|
filename = g_concat_dir_and_file (desktop_directory, dii->filename);
|
|
|
|
gmeta_set_icon_pos (filename, dii->x, dii->y);
|
|
|
|
g_free (filename);
|
1998-10-30 20:08:03 +03:00
|
|
|
}
|
|
|
|
|
1998-12-17 07:51:24 +03:00
|
|
|
/*
|
|
|
|
* Returns TRUE if there is already an icon in the desktop for the
|
|
|
|
* specified filename, FALSE otherwise.
|
|
|
|
*/
|
1998-12-07 00:01:30 +03:00
|
|
|
static int
|
|
|
|
icon_exists (char *filename)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
GList *l;
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *dii;
|
1998-12-07 00:01:30 +03:00
|
|
|
|
|
|
|
for (i = 0; i < (layout_cols * layout_rows); i++)
|
|
|
|
for (l = layout_slots[i].icons; l; l = l->next) {
|
|
|
|
dii = l->data;
|
|
|
|
if (strcmp (filename, dii->filename) == 0)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1998-12-30 05:51:01 +03:00
|
|
|
static GList *
|
|
|
|
icon_exists_in_list (GList *list, char *filename)
|
|
|
|
{
|
|
|
|
GList *l;
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *dii;
|
1998-12-30 05:51:01 +03:00
|
|
|
|
1998-12-31 04:43:11 +03:00
|
|
|
for (l = list; l; l = l->next) {
|
|
|
|
dii = l->data;
|
1998-12-30 05:51:01 +03:00
|
|
|
|
|
|
|
if (strcmp (filename, dii->filename) == 0)
|
|
|
|
return l;
|
|
|
|
}
|
1998-12-31 04:43:11 +03:00
|
|
|
|
1998-12-30 05:51:01 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1998-12-17 07:51:24 +03:00
|
|
|
/*
|
1998-12-30 05:51:01 +03:00
|
|
|
* Returns a GList with all of the icons on the desktop
|
|
|
|
*/
|
|
|
|
GList *
|
|
|
|
desktop_get_all_icons (void)
|
|
|
|
{
|
|
|
|
GList *l, *res;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
res = NULL;
|
|
|
|
for (i = 0; i < (layout_cols * layout_rows); i++)
|
|
|
|
for (l = layout_slots [i].icons; l; l = l->next){
|
|
|
|
res = g_list_prepend (res, l->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reads the ~/desktop directory and creates the desktop icons. If
|
1998-12-17 07:51:24 +03:00
|
|
|
* incremental is TRUE, then an icon will not be created for a file if
|
|
|
|
* there is already an icon for it, and icons will be created starting
|
|
|
|
* at the specified position.
|
1998-12-07 00:01:30 +03:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
load_desktop_icons (int incremental, int xpos, int ypos)
|
|
|
|
{
|
|
|
|
struct dirent *dirent;
|
|
|
|
DIR *dir;
|
|
|
|
char *full_name;
|
|
|
|
int have_pos, x, y;
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *dii;
|
1998-12-07 00:01:30 +03:00
|
|
|
GSList *need_position_list, *l;
|
1998-12-30 05:51:01 +03:00
|
|
|
GList *all_icons;
|
1998-12-07 00:01:30 +03:00
|
|
|
|
|
|
|
dir = mc_opendir (desktop_directory);
|
|
|
|
if (!dir) {
|
|
|
|
message (FALSE,
|
|
|
|
_("Warning"),
|
|
|
|
_("Could not open %s; will not have initial desktop icons"),
|
|
|
|
desktop_directory);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-12-30 05:51:01 +03:00
|
|
|
/*
|
|
|
|
* First create the icons for all the files that do have their
|
|
|
|
* icon position set. Build a list of the icons that do not
|
|
|
|
* have their position set.
|
1998-12-07 00:01:30 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
need_position_list = NULL;
|
|
|
|
|
1998-12-30 05:51:01 +03:00
|
|
|
all_icons = desktop_get_all_icons ();
|
|
|
|
|
1998-12-07 00:01:30 +03:00
|
|
|
while ((dirent = mc_readdir (dir)) != NULL) {
|
|
|
|
if (((dirent->d_name[0] == '.') && (dirent->d_name[1] == 0))
|
|
|
|
|| ((dirent->d_name[0] == '.') && (dirent->d_name[1] == '.') && (dirent->d_name[2] == 0)))
|
|
|
|
continue;
|
|
|
|
|
1998-12-30 05:51:01 +03:00
|
|
|
if (incremental){
|
|
|
|
GList *element;
|
|
|
|
|
|
|
|
element = icon_exists_in_list (all_icons, dirent->d_name);
|
|
|
|
|
|
|
|
if (element){
|
|
|
|
g_list_remove_link (all_icons, element);
|
|
|
|
continue;
|
|
|
|
}
|
1998-12-07 00:01:30 +03:00
|
|
|
|
1998-12-30 05:51:01 +03:00
|
|
|
}
|
|
|
|
|
1998-12-07 00:01:30 +03:00
|
|
|
full_name = g_concat_dir_and_file (desktop_directory, dirent->d_name);
|
|
|
|
|
|
|
|
have_pos = gmeta_get_icon_pos (full_name, &x, &y);
|
|
|
|
|
|
|
|
if (have_pos) {
|
|
|
|
dii = desktop_icon_info_new (dirent->d_name, FALSE, x, y);
|
|
|
|
gtk_widget_show (dii->dicon);
|
|
|
|
|
|
|
|
g_free (full_name);
|
|
|
|
} else
|
|
|
|
need_position_list = g_slist_prepend (need_position_list, g_strdup (dirent->d_name));
|
|
|
|
}
|
|
|
|
|
|
|
|
mc_closedir (dir);
|
|
|
|
|
1998-12-30 05:51:01 +03:00
|
|
|
/*
|
|
|
|
* all_icons now contains a list of all of the icons that were not found
|
|
|
|
* in the ~/desktop directory, remove them.
|
|
|
|
*/
|
|
|
|
if (incremental){
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
for (l = all_icons; l; l = l->next){
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *dii = l->data;
|
1998-12-30 05:51:01 +03:00
|
|
|
|
|
|
|
desktop_icon_destroy (dii);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_list_free (all_icons);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now create the icons for all the files that did not have their position set. This makes
|
1998-12-07 00:01:30 +03:00
|
|
|
* auto-placement work correctly without overlapping icons.
|
|
|
|
*/
|
|
|
|
|
|
|
|
need_position_list = g_slist_reverse (need_position_list);
|
|
|
|
|
|
|
|
for (l = need_position_list; l; l = l->next) {
|
|
|
|
dii = desktop_icon_info_new (l->data, TRUE, xpos, ypos);
|
|
|
|
gtk_widget_show (dii->dicon);
|
|
|
|
g_free (l->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free (need_position_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Destroys all the current desktop icons */
|
|
|
|
static void
|
|
|
|
destroy_desktop_icons (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
GList *l;
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *dii;
|
1998-12-07 00:01:30 +03:00
|
|
|
|
|
|
|
for (i = 0; i < (layout_cols * layout_rows); i++) {
|
|
|
|
l = layout_slots[i].icons;
|
|
|
|
|
|
|
|
while (l) {
|
|
|
|
dii = l->data;
|
|
|
|
l = l->next;
|
|
|
|
|
1998-12-30 05:51:01 +03:00
|
|
|
desktop_icon_destroy (dii);
|
1998-12-07 00:01:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-17 07:51:24 +03:00
|
|
|
/*
|
|
|
|
* Reloads the desktop icons. If incremental is TRUE, then the
|
|
|
|
* existing icons will not be destroyed first, and the new icons will
|
|
|
|
* be put at the specified position.
|
1998-12-07 00:01:30 +03:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
reload_desktop_icons (int incremental, int x, int y)
|
|
|
|
{
|
|
|
|
if (!incremental)
|
|
|
|
destroy_desktop_icons ();
|
|
|
|
|
|
|
|
load_desktop_icons (incremental, x, y);
|
1998-12-30 05:51:01 +03:00
|
|
|
x_flush_events ();
|
1998-12-07 00:01:30 +03:00
|
|
|
}
|
|
|
|
|
1998-12-11 05:05:19 +03:00
|
|
|
/* Unselects all the desktop icons except the one in exclude */
|
1998-11-02 02:21:24 +03:00
|
|
|
static void
|
1998-12-31 04:43:11 +03:00
|
|
|
unselect_all (DesktopIconInfo *exclude)
|
1998-11-02 02:21:24 +03:00
|
|
|
{
|
1998-11-03 04:32:38 +03:00
|
|
|
int i;
|
1998-11-02 02:21:24 +03:00
|
|
|
GList *l;
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *dii;
|
1998-11-02 02:21:24 +03:00
|
|
|
|
1998-11-03 04:32:38 +03:00
|
|
|
for (i = 0; i < (layout_cols * layout_rows); i++)
|
|
|
|
for (l = layout_slots[i].icons; l; l = l->next) {
|
|
|
|
dii = l->data;
|
1998-11-02 02:21:24 +03:00
|
|
|
|
1998-12-11 05:05:19 +03:00
|
|
|
if (dii->selected && dii != exclude) {
|
1998-11-03 04:32:38 +03:00
|
|
|
desktop_icon_select (DESKTOP_ICON (dii->dicon), FALSE);
|
|
|
|
dii->selected = FALSE;
|
|
|
|
}
|
1998-11-02 02:21:24 +03:00
|
|
|
}
|
1998-11-03 04:32:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets the selection state of a range to the specified value. The range starts at the
|
|
|
|
* last_selected_icon and ends at the specified icon.
|
|
|
|
*/
|
|
|
|
static void
|
1998-12-31 04:43:11 +03:00
|
|
|
select_range (DesktopIconInfo *dii, int sel)
|
1998-11-03 04:32:38 +03:00
|
|
|
{
|
1998-11-03 19:29:47 +03:00
|
|
|
int du, dv, lu, lv;
|
|
|
|
int min_u, min_v;
|
|
|
|
int max_u, max_v;
|
|
|
|
int u, v;
|
1998-11-03 04:32:38 +03:00
|
|
|
GList *l;
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *ldii;
|
|
|
|
DesktopIconInfo *min_udii, *min_vdii;
|
|
|
|
DesktopIconInfo *max_udii, *max_vdii;
|
1998-11-03 04:32:38 +03:00
|
|
|
|
|
|
|
/* Find out the selection range */
|
|
|
|
|
|
|
|
if (!last_selected_icon)
|
|
|
|
last_selected_icon = dii;
|
|
|
|
|
1998-11-03 19:29:47 +03:00
|
|
|
du = dii->slot / layout_rows;
|
|
|
|
dv = dii->slot % layout_rows;
|
|
|
|
lu = last_selected_icon->slot / layout_rows;
|
|
|
|
lv = last_selected_icon->slot % layout_rows;
|
|
|
|
|
|
|
|
if (du < lu) {
|
|
|
|
min_u = du;
|
|
|
|
max_u = lu;
|
|
|
|
min_udii = dii;
|
|
|
|
max_udii = last_selected_icon;
|
1998-11-03 04:32:38 +03:00
|
|
|
} else {
|
1998-11-03 19:29:47 +03:00
|
|
|
min_u = lu;
|
|
|
|
max_u = du;
|
|
|
|
min_udii = last_selected_icon;
|
|
|
|
max_udii = dii;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dv < lv) {
|
|
|
|
min_v = dv;
|
|
|
|
max_v = lv;
|
|
|
|
min_vdii = dii;
|
|
|
|
max_vdii = last_selected_icon;
|
|
|
|
} else {
|
|
|
|
min_v = lv;
|
|
|
|
max_v = dv;
|
|
|
|
min_vdii = last_selected_icon;
|
|
|
|
max_vdii = dii;
|
1998-11-02 02:21:24 +03:00
|
|
|
}
|
1998-11-03 04:32:38 +03:00
|
|
|
|
1998-11-04 19:51:57 +03:00
|
|
|
/* Select all the icons in the rectangle */
|
1998-11-03 04:32:38 +03:00
|
|
|
|
1998-11-03 19:29:47 +03:00
|
|
|
for (u = min_u; u <= max_u; u++)
|
|
|
|
for (v = min_v; v <= max_v; v++)
|
|
|
|
for (l = l_slots (u, v).icons; l; l = l->next) {
|
|
|
|
ldii = l->data;
|
1998-11-03 04:32:38 +03:00
|
|
|
|
1998-11-03 19:29:47 +03:00
|
|
|
if ((u == min_u && ldii->x < min_udii->x)
|
|
|
|
|| (v == min_v && ldii->y < min_vdii->y)
|
|
|
|
|| (u == max_u && ldii->x > max_udii->x)
|
|
|
|
|| (v == max_v && ldii->y > max_vdii->y))
|
|
|
|
continue;
|
1998-11-03 04:32:38 +03:00
|
|
|
|
1998-11-03 19:29:47 +03:00
|
|
|
desktop_icon_select (DESKTOP_ICON (ldii->dicon), sel);
|
|
|
|
ldii->selected = sel;
|
|
|
|
}
|
1998-11-02 02:21:24 +03:00
|
|
|
}
|
|
|
|
|
1998-12-17 07:51:24 +03:00
|
|
|
/*
|
|
|
|
* Handles icon selection and unselection due to button presses. The
|
1998-12-11 05:05:19 +03:00
|
|
|
* event_state is the state field of the event.
|
|
|
|
*/
|
1998-11-02 02:21:24 +03:00
|
|
|
static void
|
1998-12-31 04:43:11 +03:00
|
|
|
select_icon (DesktopIconInfo *dii, int event_state)
|
1998-11-02 02:21:24 +03:00
|
|
|
{
|
1998-11-03 04:32:38 +03:00
|
|
|
int range;
|
|
|
|
int additive;
|
|
|
|
|
1998-12-11 05:05:19 +03:00
|
|
|
range = ((event_state & GDK_SHIFT_MASK) != 0);
|
|
|
|
additive = ((event_state & GDK_CONTROL_MASK) != 0);
|
1998-11-03 04:32:38 +03:00
|
|
|
|
|
|
|
if (!additive)
|
1998-12-11 05:05:19 +03:00
|
|
|
unselect_all (NULL);
|
1998-11-03 04:32:38 +03:00
|
|
|
|
|
|
|
if (!range) {
|
|
|
|
if (additive) {
|
|
|
|
desktop_icon_select (DESKTOP_ICON (dii->dicon), !dii->selected);
|
|
|
|
dii->selected = !dii->selected;
|
|
|
|
} else if (!dii->selected) {
|
|
|
|
desktop_icon_select (DESKTOP_ICON (dii->dicon), TRUE);
|
|
|
|
dii->selected = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
last_selected_icon = dii;
|
1998-11-04 19:51:57 +03:00
|
|
|
|
|
|
|
if (dii->selected)
|
|
|
|
gdk_window_raise (dii->dicon->window);
|
1998-11-03 04:32:38 +03:00
|
|
|
} else
|
|
|
|
select_range (dii, TRUE);
|
1998-11-02 02:21:24 +03:00
|
|
|
}
|
|
|
|
|
1998-12-07 00:01:30 +03:00
|
|
|
/* Creates a file entry structure and fills it with information appropriate to the specified file. */
|
|
|
|
static file_entry *
|
|
|
|
file_entry_from_file (char *filename)
|
|
|
|
{
|
1998-12-07 05:36:47 +03:00
|
|
|
file_entry *fe;
|
|
|
|
struct stat s;
|
|
|
|
|
|
|
|
if (mc_lstat (filename, &s) == -1) {
|
|
|
|
g_warning ("Could not stat %s, bad things will happen", filename);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
fe = g_new (file_entry, 1);
|
|
|
|
fe->fname = g_strdup (x_basename (filename));
|
|
|
|
fe->fnamelen = strlen (fe->fname);
|
|
|
|
fe->buf = s;
|
|
|
|
fe->f.marked = FALSE;
|
|
|
|
fe->f.link_to_dir = FALSE;
|
|
|
|
fe->f.stalled_link = FALSE;
|
|
|
|
|
|
|
|
if (S_ISLNK (s.st_mode)) {
|
|
|
|
struct stat s2;
|
|
|
|
|
|
|
|
if (mc_stat (filename, &s2) == 0)
|
|
|
|
fe->f.link_to_dir = S_ISDIR (s2.st_mode) != 0;
|
|
|
|
else
|
|
|
|
fe->f.stalled_link = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fe;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Frees a file entry structure */
|
|
|
|
static void
|
|
|
|
file_entry_free (file_entry *fe)
|
|
|
|
{
|
|
|
|
if (fe->fname)
|
|
|
|
g_free (fe->fname);
|
1998-12-07 00:01:30 +03:00
|
|
|
|
1998-12-07 05:36:47 +03:00
|
|
|
g_free (fe);
|
1998-12-07 00:01:30 +03:00
|
|
|
}
|
|
|
|
|
1998-12-17 07:51:24 +03:00
|
|
|
/*
|
|
|
|
* Callback used when an icon's text changes. We must validate the
|
|
|
|
* rename and return the appropriate value. The desktop icon info
|
|
|
|
* structure is passed in the user data.
|
1998-11-06 02:24:47 +03:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
text_changed (GnomeIconTextItem *iti, gpointer data)
|
|
|
|
{
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *dii;
|
1998-11-07 04:19:53 +03:00
|
|
|
char *new_name;
|
1998-11-06 02:24:47 +03:00
|
|
|
char *source;
|
|
|
|
char *dest;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
dii = data;
|
|
|
|
|
|
|
|
source = g_concat_dir_and_file (desktop_directory, dii->filename);
|
1998-11-07 04:19:53 +03:00
|
|
|
new_name = gnome_icon_text_item_get_text (iti);
|
|
|
|
dest = g_concat_dir_and_file (desktop_directory, new_name);
|
1998-11-06 02:24:47 +03:00
|
|
|
|
1998-11-07 04:19:53 +03:00
|
|
|
if (mc_rename (source, dest) == 0) {
|
|
|
|
g_free (dii->filename);
|
|
|
|
dii->filename = g_strdup (new_name);
|
1998-11-06 02:24:47 +03:00
|
|
|
retval = TRUE;
|
1998-11-07 04:19:53 +03:00
|
|
|
} else
|
1998-11-06 02:24:47 +03:00
|
|
|
retval = FALSE; /* FIXME: maybe pop up a warning/query dialog? */
|
|
|
|
|
|
|
|
g_free (source);
|
|
|
|
g_free (dest);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
1998-12-17 07:51:24 +03:00
|
|
|
/*
|
|
|
|
* Callback used when the user begins editing the icon text item in a
|
|
|
|
* desktop icon. It installs the mouse and keyboard grabs that are
|
|
|
|
* required while an icon is being edited.
|
1998-11-05 02:01:24 +03:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
editing_started (GnomeIconTextItem *iti, gpointer data)
|
|
|
|
{
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *dii;
|
1998-11-05 02:01:24 +03:00
|
|
|
GdkCursor *ibeam;
|
|
|
|
|
|
|
|
dii = data;
|
|
|
|
|
1998-12-11 06:18:41 +03:00
|
|
|
/* Disable drags from this icon until editing is finished */
|
|
|
|
|
|
|
|
gtk_drag_source_unset (DESKTOP_ICON (dii->dicon)->canvas);
|
|
|
|
|
1998-12-11 05:05:19 +03:00
|
|
|
/* Unselect all icons but this one */
|
|
|
|
unselect_all (dii);
|
|
|
|
|
1998-11-05 02:01:24 +03:00
|
|
|
ibeam = gdk_cursor_new (GDK_XTERM);
|
1998-12-11 11:58:26 +03:00
|
|
|
gdk_pointer_grab (dii->dicon->window,
|
|
|
|
TRUE,
|
1998-11-05 02:01:24 +03:00
|
|
|
(GDK_BUTTON_PRESS_MASK
|
|
|
|
| GDK_BUTTON_RELEASE_MASK
|
|
|
|
| GDK_POINTER_MOTION_MASK
|
|
|
|
| GDK_ENTER_NOTIFY_MASK
|
|
|
|
| GDK_LEAVE_NOTIFY_MASK),
|
|
|
|
NULL,
|
|
|
|
ibeam,
|
|
|
|
GDK_CURRENT_TIME);
|
1998-12-11 11:58:26 +03:00
|
|
|
gtk_grab_add (dii->dicon);
|
1998-11-05 02:01:24 +03:00
|
|
|
gdk_cursor_destroy (ibeam);
|
|
|
|
|
|
|
|
gdk_keyboard_grab (GTK_LAYOUT (DESKTOP_ICON (dii->dicon)->canvas)->bin_window, FALSE, GDK_CURRENT_TIME);
|
|
|
|
}
|
|
|
|
|
1998-12-11 06:18:41 +03:00
|
|
|
/* Sets up the specified icon as a drag source, but does not connect the signals */
|
|
|
|
static void
|
1998-12-31 04:43:11 +03:00
|
|
|
setup_icon_dnd_actions (DesktopIconInfo *dii)
|
1998-12-11 06:18:41 +03:00
|
|
|
{
|
|
|
|
gtk_drag_source_set (DESKTOP_ICON (dii->dicon)->canvas,
|
|
|
|
GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
|
|
|
|
dnd_icon_sources,
|
|
|
|
dnd_icon_nsources,
|
|
|
|
GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_ASK);
|
|
|
|
}
|
|
|
|
|
1998-12-17 07:51:24 +03:00
|
|
|
/*
|
|
|
|
* Callback used when the user finishes editing the icon text item in
|
|
|
|
* a desktop icon. It removes the mouse and keyboard grabs.
|
1998-11-05 02:01:24 +03:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
editing_stopped (GnomeIconTextItem *iti, gpointer data)
|
|
|
|
{
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *dii;
|
1998-12-11 05:05:19 +03:00
|
|
|
|
|
|
|
dii = data;
|
|
|
|
|
1998-12-11 11:58:26 +03:00
|
|
|
gtk_grab_remove (dii->dicon);
|
1998-11-05 02:01:24 +03:00
|
|
|
gdk_pointer_ungrab (GDK_CURRENT_TIME);
|
|
|
|
gdk_keyboard_ungrab (GDK_CURRENT_TIME);
|
1998-12-11 06:18:41 +03:00
|
|
|
|
|
|
|
/* Re-enable drags from this icon */
|
|
|
|
|
|
|
|
setup_icon_dnd_actions (dii);
|
1998-11-05 02:01:24 +03:00
|
|
|
}
|
|
|
|
|
1998-12-11 05:05:19 +03:00
|
|
|
/* Used to open a desktop icon when the user double-clicks on it */
|
1998-12-30 05:51:01 +03:00
|
|
|
void
|
1998-12-31 04:43:11 +03:00
|
|
|
desktop_icon_open (DesktopIconInfo *dii)
|
1998-12-11 05:05:19 +03:00
|
|
|
{
|
|
|
|
char *filename;
|
|
|
|
file_entry *fe;
|
|
|
|
|
|
|
|
filename = g_concat_dir_and_file (desktop_directory, dii->filename);
|
|
|
|
|
|
|
|
fe = file_entry_from_file (filename);
|
|
|
|
|
|
|
|
if (S_ISDIR (fe->buf.st_mode) || link_isdir (fe))
|
|
|
|
new_panel_at (filename);
|
|
|
|
else
|
|
|
|
do_enter_on_file_entry (fe);
|
|
|
|
|
|
|
|
file_entry_free (fe);
|
|
|
|
}
|
|
|
|
|
1998-12-30 05:51:01 +03:00
|
|
|
void
|
1998-12-31 04:43:11 +03:00
|
|
|
desktop_icon_delete (DesktopIconInfo *dii)
|
1998-12-30 05:51:01 +03:00
|
|
|
{
|
|
|
|
char *full_name;
|
|
|
|
struct stat s;
|
|
|
|
long progress_count = 0;
|
|
|
|
double progress_bytes = 0;
|
|
|
|
|
|
|
|
/* 1. Delete the file */
|
|
|
|
create_op_win (OP_DELETE, 1);
|
|
|
|
x_flush_events ();
|
|
|
|
|
|
|
|
full_name = g_concat_dir_and_file (desktop_directory, dii->filename);
|
|
|
|
stat (full_name, &s);
|
|
|
|
if (S_ISDIR (s.st_mode))
|
|
|
|
erase_dir (full_name, &progress_count, &progress_bytes);
|
|
|
|
else
|
|
|
|
erase_file (full_name, &progress_count, &progress_bytes, TRUE);
|
|
|
|
g_free (full_name);
|
|
|
|
destroy_op_win ();
|
|
|
|
|
|
|
|
/* 2. Destroy the dicon */
|
|
|
|
desktop_icon_destroy (dii);
|
|
|
|
}
|
|
|
|
|
1998-12-11 05:05:19 +03:00
|
|
|
/* Used to execute the popup menu for desktop icons */
|
|
|
|
static void
|
1998-12-31 04:43:11 +03:00
|
|
|
do_popup_menu (DesktopIconInfo *dii, GdkEventButton *event)
|
1998-12-11 05:05:19 +03:00
|
|
|
{
|
|
|
|
char *filename;
|
|
|
|
|
|
|
|
filename = g_concat_dir_and_file (desktop_directory, dii->filename);
|
|
|
|
|
1998-12-22 02:29:46 +03:00
|
|
|
if (gpopup_do_popup (event, NULL, dii, 0, filename) != -1)
|
1998-12-30 05:51:01 +03:00
|
|
|
reload_desktop_icons (TRUE, 0, 0); /* bleah */
|
1998-12-11 05:05:19 +03:00
|
|
|
|
|
|
|
g_free (filename);
|
|
|
|
}
|
|
|
|
|
1998-12-11 11:58:26 +03:00
|
|
|
/* Callback activated when a button is redirected from the desktop to
|
|
|
|
* the icon during a grab.
|
|
|
|
*/
|
|
|
|
static gint
|
|
|
|
window_button_press (GtkWidget *widget, GdkEventButton *event, gpointer data)
|
|
|
|
{
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *dii;
|
1998-12-11 20:49:09 +03:00
|
|
|
GtkWidget *parent;
|
1998-12-11 11:58:26 +03:00
|
|
|
|
|
|
|
dii = data;
|
|
|
|
|
1998-12-11 20:49:09 +03:00
|
|
|
/* We should only get this while editing. But check anyways -
|
|
|
|
* we ignore events in a child of our a event widget
|
|
|
|
*/
|
|
|
|
parent = gtk_get_event_widget ((GdkEvent *)event);
|
|
|
|
if (parent)
|
|
|
|
parent = parent->parent;
|
|
|
|
|
|
|
|
while (parent) {
|
|
|
|
if (widget == parent)
|
|
|
|
return FALSE;
|
|
|
|
parent = parent->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GNOME_ICON_TEXT_ITEM (DESKTOP_ICON (dii->dicon)->text)->editing) {
|
1998-12-11 11:58:26 +03:00
|
|
|
gnome_icon_text_item_stop_editing (
|
|
|
|
GNOME_ICON_TEXT_ITEM (
|
|
|
|
DESKTOP_ICON (dii->dicon)->text), TRUE);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1998-12-11 05:05:19 +03:00
|
|
|
/* Callback used when a button is pressed on a desktop icon */
|
1998-12-05 04:01:13 +03:00
|
|
|
static gint
|
1998-12-11 05:05:19 +03:00
|
|
|
icon_button_press (GtkWidget *widget, GdkEventButton *event, gpointer data)
|
1998-12-05 04:01:13 +03:00
|
|
|
{
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *dii;
|
1998-12-11 05:05:19 +03:00
|
|
|
int retval;
|
1998-12-05 04:01:13 +03:00
|
|
|
|
|
|
|
dii = data;
|
1998-12-11 05:05:19 +03:00
|
|
|
|
1998-12-11 06:18:41 +03:00
|
|
|
/* If the text is being edited, do not handle clicks by ourselves */
|
|
|
|
|
|
|
|
if (GNOME_ICON_TEXT_ITEM (DESKTOP_ICON (dii->dicon)->text)->editing)
|
|
|
|
return FALSE;
|
|
|
|
|
1998-12-11 05:05:19 +03:00
|
|
|
/* Save the mouse position for DnD */
|
|
|
|
|
1998-12-08 00:07:27 +03:00
|
|
|
dnd_press_x = event->x;
|
|
|
|
dnd_press_y = event->y;
|
1998-12-05 04:01:13 +03:00
|
|
|
|
1998-12-11 05:05:19 +03:00
|
|
|
/* Process the event */
|
|
|
|
|
|
|
|
retval = FALSE;
|
|
|
|
|
|
|
|
switch (event->type) {
|
|
|
|
case GDK_BUTTON_PRESS:
|
|
|
|
if (event->button == 1) {
|
|
|
|
/* If (only) the Control key is down, then we have to delay the icon selection */
|
|
|
|
|
|
|
|
dnd_select_icon_pending = ((event->state & GDK_CONTROL_MASK)
|
|
|
|
&& !((event->state & GDK_CONTROL_MASK)
|
|
|
|
&& (event->state & GDK_SHIFT_MASK)));
|
|
|
|
|
|
|
|
if (!dnd_select_icon_pending) {
|
|
|
|
select_icon (dii, event->state);
|
|
|
|
retval = TRUE;
|
|
|
|
}
|
|
|
|
} else if (event->button == 3) {
|
|
|
|
do_popup_menu (dii, event);
|
|
|
|
retval = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_2BUTTON_PRESS:
|
|
|
|
if (event->button != 1)
|
|
|
|
break;
|
|
|
|
|
1998-12-30 05:51:01 +03:00
|
|
|
desktop_icon_open (dii);
|
1998-12-11 05:05:19 +03:00
|
|
|
retval = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Keep the canvas items from getting the signal */
|
|
|
|
#if 0
|
|
|
|
if (retval)
|
|
|
|
gtk_signal_emit_stop_by_name (GTK_OBJECT (DESKTOP_ICON (dii->dicon)->canvas), "button_press_event");
|
|
|
|
#endif
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handler for button releases on desktop icons. If there was a pending
|
|
|
|
* selection on the icon, then the function performs the selection.
|
|
|
|
*/
|
|
|
|
static gint
|
|
|
|
icon_button_release (GtkWidget *widget, GdkEventButton *event, gpointer data)
|
|
|
|
{
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *dii;
|
1998-12-11 05:05:19 +03:00
|
|
|
|
|
|
|
dii = data;
|
|
|
|
|
|
|
|
if (dnd_select_icon_pending) {
|
|
|
|
select_icon (dii, GDK_CONTROL_MASK);
|
|
|
|
dnd_select_icon_pending = FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
1998-12-11 11:58:26 +03:00
|
|
|
} else if (GNOME_ICON_TEXT_ITEM (DESKTOP_ICON (dii->dicon)->text)->selecting) {
|
|
|
|
dii->finishing_selection = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handler for button releases on desktop icons. If there was a pending
|
|
|
|
* selection on the icon, then the function performs the selection.
|
|
|
|
*/
|
|
|
|
static gint
|
|
|
|
icon_button_release_after (GtkWidget *widget, GdkEventButton *event, gpointer data)
|
|
|
|
{
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *dii;
|
1998-12-11 11:58:26 +03:00
|
|
|
|
|
|
|
dii = data;
|
|
|
|
|
|
|
|
if (dii->finishing_selection) {
|
|
|
|
/* Restore the pointer grab here because the icon item just
|
|
|
|
* called gdk_pointer_ungrab()
|
|
|
|
*/
|
|
|
|
GdkCursor *ibeam = gdk_cursor_new (GDK_XTERM);
|
|
|
|
gdk_pointer_grab (dii->dicon->window,
|
|
|
|
TRUE,
|
|
|
|
(GDK_BUTTON_PRESS_MASK
|
|
|
|
| GDK_BUTTON_RELEASE_MASK
|
|
|
|
| GDK_POINTER_MOTION_MASK
|
|
|
|
| GDK_ENTER_NOTIFY_MASK
|
|
|
|
| GDK_LEAVE_NOTIFY_MASK),
|
|
|
|
NULL,
|
|
|
|
ibeam,
|
|
|
|
GDK_CURRENT_TIME);
|
|
|
|
gdk_cursor_destroy (ibeam);
|
|
|
|
|
|
|
|
dii->finishing_selection = FALSE;
|
1998-12-11 05:05:19 +03:00
|
|
|
}
|
|
|
|
|
1998-12-05 04:01:13 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Callback used when a drag from the desktop icons is started. We set the drag icon to the proper
|
|
|
|
* pixmap.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
drag_begin (GtkWidget *widget, GdkDragContext *context, gpointer data)
|
|
|
|
{
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *dii;
|
1998-12-05 04:01:13 +03:00
|
|
|
DesktopIcon *dicon;
|
|
|
|
GtkArg args[3];
|
|
|
|
GdkImlibImage *im;
|
|
|
|
GdkPixmap *pixmap;
|
|
|
|
GdkBitmap *mask;
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
dii = data;
|
|
|
|
dicon = DESKTOP_ICON (dii->dicon);
|
|
|
|
|
1998-12-11 05:05:19 +03:00
|
|
|
/* See if the icon was pending to be selected */
|
|
|
|
|
|
|
|
if (dnd_select_icon_pending) {
|
|
|
|
if (!dii->selected)
|
|
|
|
select_icon (dii, GDK_CONTROL_MASK);
|
|
|
|
|
|
|
|
dnd_select_icon_pending = FALSE;
|
|
|
|
}
|
|
|
|
|
1998-12-05 04:01:13 +03:00
|
|
|
/* FIXME: see if it is more than one icon and if so, use a multiple-files icon. */
|
|
|
|
|
|
|
|
args[0].name = "image";
|
|
|
|
args[1].name = "x";
|
|
|
|
args[2].name = "y";
|
|
|
|
gtk_object_getv (GTK_OBJECT (dicon->icon), 3, args);
|
|
|
|
im = GTK_VALUE_BOXED (args[0]);
|
|
|
|
x = GTK_VALUE_DOUBLE (args[1]);
|
|
|
|
y = GTK_VALUE_DOUBLE (args[2]);
|
|
|
|
|
|
|
|
gdk_imlib_render (im, im->rgb_width, im->rgb_height);
|
|
|
|
pixmap = gdk_imlib_copy_image (im);
|
|
|
|
mask = gdk_imlib_copy_mask (im);
|
|
|
|
|
|
|
|
gtk_drag_set_icon_pixmap (context,
|
|
|
|
gtk_widget_get_colormap (dicon->canvas),
|
|
|
|
pixmap,
|
|
|
|
mask,
|
1998-12-08 00:07:27 +03:00
|
|
|
dnd_press_x - x,
|
|
|
|
dnd_press_y - y);
|
1998-12-05 04:01:13 +03:00
|
|
|
|
|
|
|
gdk_pixmap_unref (pixmap);
|
|
|
|
gdk_bitmap_unref (mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Builds a string with the URI-list of the selected desktop icons */
|
|
|
|
static char *
|
|
|
|
build_selected_icons_uri_list (int *len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
GList *l;
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *dii;
|
1998-12-05 04:01:13 +03:00
|
|
|
char *filelist, *p;
|
|
|
|
int desktop_dir_len;
|
|
|
|
|
|
|
|
/* First, count the number of selected icons and add up their filename lengths */
|
|
|
|
|
|
|
|
*len = 0;
|
|
|
|
desktop_dir_len = strlen (desktop_directory);
|
|
|
|
|
|
|
|
for (i = 0; i < (layout_cols * layout_rows); i++)
|
|
|
|
for (l = layout_slots[i].icons; l; l = l->next) {
|
|
|
|
dii = l->data;
|
|
|
|
|
|
|
|
/* "file:" + desktop_directory + "/" + dii->filename + "\r\n" */
|
|
|
|
|
|
|
|
if (dii->selected)
|
|
|
|
*len += 5 + desktop_dir_len + 1 + strlen (dii->filename) + 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Second, create the file list string */
|
|
|
|
|
|
|
|
filelist = g_new (char, *len + 1); /* plus 1 for null terminator */
|
|
|
|
p = filelist;
|
|
|
|
|
|
|
|
for (i = 0; i < (layout_cols * layout_rows); i++)
|
|
|
|
for (l = layout_slots[i].icons; l; l = l->next) {
|
|
|
|
dii = l->data;
|
|
|
|
|
|
|
|
if (dii->selected) {
|
|
|
|
strcpy (p, "file:");
|
|
|
|
p += 5;
|
|
|
|
|
|
|
|
strcpy (p, desktop_directory);
|
|
|
|
p += desktop_dir_len;
|
|
|
|
|
|
|
|
*p++ = '/';
|
|
|
|
|
|
|
|
strcpy (p, dii->filename);
|
|
|
|
p += strlen (dii->filename);
|
|
|
|
|
|
|
|
strcpy (p, "\r\n");
|
|
|
|
p += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*p = 0;
|
|
|
|
|
|
|
|
return filelist;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Callback used to get the drag data from the desktop icons */
|
|
|
|
static void
|
|
|
|
drag_data_get (GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data,
|
|
|
|
guint info, guint32 time, gpointer data)
|
|
|
|
{
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *dii;
|
1998-12-05 04:01:13 +03:00
|
|
|
char *filelist;
|
|
|
|
int len;
|
1998-12-11 21:12:21 +03:00
|
|
|
GList *files;
|
1998-12-05 04:01:13 +03:00
|
|
|
|
|
|
|
dii = data;
|
1998-12-11 21:12:21 +03:00
|
|
|
filelist = build_selected_icons_uri_list (&len);
|
1998-12-05 04:01:13 +03:00
|
|
|
|
|
|
|
switch (info) {
|
|
|
|
case TARGET_MC_DESKTOP_ICON:
|
|
|
|
case TARGET_URI_LIST:
|
|
|
|
case TARGET_TEXT_PLAIN:
|
|
|
|
gtk_selection_data_set (selection_data,
|
|
|
|
selection_data->target,
|
|
|
|
8,
|
|
|
|
filelist,
|
|
|
|
len);
|
1998-12-11 21:12:21 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TARGET_URL:
|
|
|
|
files = gnome_uri_list_extract_uris (filelist);
|
|
|
|
if (files) {
|
|
|
|
gtk_selection_data_set (selection_data,
|
|
|
|
selection_data->target,
|
|
|
|
8,
|
|
|
|
files->data,
|
|
|
|
strlen (files->data));
|
|
|
|
}
|
|
|
|
gnome_uri_list_free_strings (files);
|
1998-12-05 04:01:13 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
1998-12-11 21:12:21 +03:00
|
|
|
|
|
|
|
g_free (filelist);
|
1998-12-05 04:01:13 +03:00
|
|
|
}
|
|
|
|
|
1998-12-08 04:31:17 +03:00
|
|
|
/* Set up a desktop icon as a DnD source */
|
|
|
|
static void
|
1998-12-31 04:43:11 +03:00
|
|
|
setup_icon_dnd_source (DesktopIconInfo *dii)
|
1998-12-08 04:31:17 +03:00
|
|
|
{
|
1998-12-11 06:18:41 +03:00
|
|
|
setup_icon_dnd_actions (dii);
|
1998-12-08 04:31:17 +03:00
|
|
|
|
|
|
|
gtk_signal_connect (GTK_OBJECT (DESKTOP_ICON (dii->dicon)->canvas), "drag_begin",
|
|
|
|
(GtkSignalFunc) drag_begin,
|
|
|
|
dii);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (DESKTOP_ICON (dii->dicon)->canvas), "drag_data_get",
|
|
|
|
GTK_SIGNAL_FUNC (drag_data_get),
|
|
|
|
dii);
|
|
|
|
}
|
|
|
|
|
1998-12-30 06:24:46 +03:00
|
|
|
/**
|
|
|
|
* drop_on_file_entry
|
|
|
|
*/
|
1998-12-08 04:31:17 +03:00
|
|
|
static void
|
1998-12-31 04:43:11 +03:00
|
|
|
desktop_icon_drop_uri_list (DesktopIconInfo *dii, GdkDragContext *context, GtkSelectionData *data)
|
1998-12-08 04:31:17 +03:00
|
|
|
{
|
|
|
|
char *filename;
|
|
|
|
file_entry *fe;
|
1998-12-30 06:24:46 +03:00
|
|
|
int size;
|
|
|
|
char *buf, *mime_type;
|
|
|
|
|
1998-12-08 04:31:17 +03:00
|
|
|
filename = g_concat_dir_and_file (desktop_directory, dii->filename);
|
|
|
|
|
|
|
|
fe = file_entry_from_file (filename);
|
|
|
|
if (!fe)
|
|
|
|
return; /* eek */
|
|
|
|
|
1998-12-30 06:24:46 +03:00
|
|
|
/*
|
|
|
|
* 1. If it is directory, drop the files there
|
|
|
|
*/
|
|
|
|
if (fe->f.link_to_dir){
|
|
|
|
gdnd_drop_on_directory (context, data, filename);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 2. Try to use a metadata-based drop action
|
|
|
|
*/
|
|
|
|
if (gnome_metadata_get (filename, "drop-action", &size, &buf) == 0){
|
1998-12-30 21:29:32 +03:00
|
|
|
/*action_drop (filename, buf, context, data);*/ /* Fixme: i'm undefined */
|
1998-12-30 06:24:46 +03:00
|
|
|
free (buf);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 3. Try a drop action from the mime-type
|
|
|
|
*/
|
|
|
|
mime_type = gnome_mime_type_or_default (filename, NULL);
|
|
|
|
if (mime_type){
|
|
|
|
char *action;
|
|
|
|
|
|
|
|
action = gnome_mime_get_value (mime_type, "drop-action");
|
|
|
|
|
|
|
|
if (action){
|
1998-12-30 21:29:32 +03:00
|
|
|
/*action_drop (filename, action, context, data);*/ /* Fixme: i'm undefined */
|
1998-12-30 06:24:46 +03:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 4. Executable. Try metadata keys for "open" and mime type for "open"
|
|
|
|
*/
|
|
|
|
if (is_exe (fe->buf.st_mode) && if_link_is_exe (fe)){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
file_entry_free (fe);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
icon_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y,
|
|
|
|
GtkSelectionData *data, guint info, guint time, gpointer user_data)
|
|
|
|
{
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *dii;
|
1998-12-30 06:24:46 +03:00
|
|
|
|
|
|
|
dii = user_data;
|
|
|
|
|
1998-12-08 04:31:17 +03:00
|
|
|
switch (info) {
|
|
|
|
case TARGET_URI_LIST:
|
1998-12-30 06:24:46 +03:00
|
|
|
desktop_icon_drop_uri_list (dii, context, data);
|
1998-12-08 04:31:17 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up a desktop icon as a DnD destination */
|
|
|
|
static void
|
1998-12-31 04:43:11 +03:00
|
|
|
setup_icon_dnd_dest (DesktopIconInfo *dii)
|
1998-12-08 04:31:17 +03:00
|
|
|
{
|
|
|
|
char *filename;
|
|
|
|
file_entry *fe;
|
|
|
|
int actions;
|
|
|
|
|
|
|
|
filename = g_concat_dir_and_file (desktop_directory, dii->filename);
|
|
|
|
fe = file_entry_from_file (filename);
|
|
|
|
g_free (filename);
|
|
|
|
|
|
|
|
if (!fe)
|
|
|
|
return; /* eek */
|
|
|
|
|
1998-12-11 06:18:41 +03:00
|
|
|
/* See what actions are appropriate for this icon */
|
|
|
|
|
1998-12-08 04:31:17 +03:00
|
|
|
if (fe->f.link_to_dir)
|
|
|
|
actions = GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_ASK;
|
|
|
|
else if (is_exe (fe->buf.st_mode) && if_link_is_exe (fe))
|
|
|
|
actions = GDK_ACTION_COPY;
|
|
|
|
else
|
|
|
|
actions = 0;
|
|
|
|
|
|
|
|
file_entry_free (fe);
|
|
|
|
|
|
|
|
if (!actions)
|
|
|
|
return;
|
|
|
|
|
1998-12-11 06:18:41 +03:00
|
|
|
/* Connect the drop signals */
|
|
|
|
|
1998-12-08 04:31:17 +03:00
|
|
|
gtk_drag_dest_set (DESKTOP_ICON (dii->dicon)->canvas,
|
|
|
|
GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
|
|
|
|
dnd_icon_targets,
|
|
|
|
dnd_icon_ntargets,
|
|
|
|
actions);
|
|
|
|
|
|
|
|
gtk_signal_connect (GTK_OBJECT (DESKTOP_ICON (dii->dicon)->canvas), "drag_data_received",
|
|
|
|
GTK_SIGNAL_FUNC (icon_drag_data_received),
|
|
|
|
dii);
|
|
|
|
}
|
|
|
|
|
1998-12-17 07:51:24 +03:00
|
|
|
/*
|
|
|
|
* Creates a new desktop icon. The filename is the pruned filename
|
|
|
|
* inside the desktop directory. If auto_pos is false, it will use
|
|
|
|
* the specified coordinates for the icon. Else, it will use auto-
|
|
|
|
* positioning trying to start at the specified coordinates. It does
|
|
|
|
* not show the icon.
|
1998-10-30 03:47:54 +03:00
|
|
|
*/
|
1998-12-31 04:43:11 +03:00
|
|
|
static DesktopIconInfo *
|
1998-10-30 03:47:54 +03:00
|
|
|
desktop_icon_info_new (char *filename, int auto_pos, int xpos, int ypos)
|
|
|
|
{
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *dii;
|
1998-12-09 20:23:38 +03:00
|
|
|
file_entry *fe;
|
1998-10-30 20:08:03 +03:00
|
|
|
char *full_name;
|
1998-12-09 20:23:38 +03:00
|
|
|
GdkImlibImage *icon_im;
|
1998-11-02 02:21:24 +03:00
|
|
|
|
|
|
|
/* Create the icon structure */
|
|
|
|
|
1998-12-08 04:31:17 +03:00
|
|
|
full_name = g_concat_dir_and_file (desktop_directory, filename);
|
1998-12-09 20:23:38 +03:00
|
|
|
fe = file_entry_from_file (full_name);
|
1998-12-17 07:51:24 +03:00
|
|
|
icon_im = gicon_get_icon_for_file_speed (fe, FALSE);
|
1998-10-30 20:08:03 +03:00
|
|
|
|
1998-12-31 04:43:11 +03:00
|
|
|
dii = g_new (DesktopIconInfo, 1);
|
1998-12-09 20:23:38 +03:00
|
|
|
dii->dicon = desktop_icon_new (icon_im, filename);
|
1998-11-03 04:32:38 +03:00
|
|
|
dii->x = 0;
|
|
|
|
dii->y = 0;
|
|
|
|
dii->slot = -1;
|
1998-10-30 20:08:03 +03:00
|
|
|
dii->filename = g_strdup (filename);
|
|
|
|
dii->selected = FALSE;
|
|
|
|
|
1998-12-09 20:23:38 +03:00
|
|
|
file_entry_free (fe);
|
1998-10-30 20:08:03 +03:00
|
|
|
g_free (full_name);
|
|
|
|
|
1998-11-02 02:21:24 +03:00
|
|
|
/* Connect to the icon's signals */
|
|
|
|
|
1998-12-11 11:58:26 +03:00
|
|
|
gtk_signal_connect_after (GTK_OBJECT (DESKTOP_ICON (dii->dicon)->canvas), "button_press_event",
|
1998-12-11 05:05:19 +03:00
|
|
|
(GtkSignalFunc) icon_button_press,
|
1998-11-02 02:21:24 +03:00
|
|
|
dii);
|
1998-12-11 11:58:26 +03:00
|
|
|
gtk_signal_connect (GTK_OBJECT (dii->dicon), "button_press_event",
|
|
|
|
(GtkSignalFunc) window_button_press,
|
1998-11-02 02:21:24 +03:00
|
|
|
dii);
|
1998-12-11 11:58:26 +03:00
|
|
|
gtk_signal_connect (GTK_OBJECT (DESKTOP_ICON (dii->dicon)->canvas), "button_release_event",
|
|
|
|
(GtkSignalFunc) icon_button_release,
|
|
|
|
dii);
|
|
|
|
gtk_signal_connect_after (GTK_OBJECT (DESKTOP_ICON (dii->dicon)->canvas), "button_release_event",
|
|
|
|
(GtkSignalFunc) icon_button_release_after,
|
|
|
|
dii);
|
1998-10-31 02:22:35 +03:00
|
|
|
|
1998-11-05 02:01:24 +03:00
|
|
|
/* Connect to the text item's signals */
|
|
|
|
|
1998-11-06 02:24:47 +03:00
|
|
|
gtk_signal_connect (GTK_OBJECT (DESKTOP_ICON (dii->dicon)->text), "text_changed",
|
|
|
|
(GtkSignalFunc) text_changed,
|
|
|
|
dii);
|
1998-11-05 02:01:24 +03:00
|
|
|
gtk_signal_connect (GTK_OBJECT (DESKTOP_ICON (dii->dicon)->text), "editing_started",
|
|
|
|
(GtkSignalFunc) editing_started,
|
|
|
|
dii);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (DESKTOP_ICON (dii->dicon)->text), "editing_stopped",
|
|
|
|
(GtkSignalFunc) editing_stopped,
|
|
|
|
dii);
|
|
|
|
|
1998-12-08 04:31:17 +03:00
|
|
|
/* Prepare the DnD functionality for this icon */
|
1998-12-05 04:01:13 +03:00
|
|
|
|
1998-12-08 04:31:17 +03:00
|
|
|
setup_icon_dnd_source (dii);
|
|
|
|
setup_icon_dnd_dest (dii);
|
1998-12-05 04:01:13 +03:00
|
|
|
|
1998-11-02 02:21:24 +03:00
|
|
|
/* Place the icon and append it to the list */
|
|
|
|
|
|
|
|
desktop_icon_info_place (dii, auto_pos, xpos, ypos);
|
1998-10-31 02:22:35 +03:00
|
|
|
return dii;
|
|
|
|
}
|
|
|
|
|
1998-12-17 07:51:24 +03:00
|
|
|
/*
|
|
|
|
* Frees a desktop icon information structure, and destroy the icon
|
|
|
|
* widget. Does not remove the structure from the desktop_icons list!
|
1998-10-31 02:22:35 +03:00
|
|
|
*/
|
1998-12-30 05:51:01 +03:00
|
|
|
void
|
1998-12-31 04:43:11 +03:00
|
|
|
desktop_icon_destroy (DesktopIconInfo *dii)
|
1998-10-31 02:22:35 +03:00
|
|
|
{
|
|
|
|
gtk_widget_destroy (dii->dicon);
|
1998-11-03 04:32:38 +03:00
|
|
|
remove_from_slot (dii);
|
1998-10-31 02:22:35 +03:00
|
|
|
|
|
|
|
g_free (dii->filename);
|
|
|
|
g_free (dii);
|
1998-10-30 03:47:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Creates the layout information array */
|
|
|
|
static void
|
|
|
|
create_layout_info (void)
|
|
|
|
{
|
1998-12-07 18:47:00 +03:00
|
|
|
layout_screen_width = gdk_screen_width ();
|
|
|
|
layout_screen_height = gdk_screen_height ();
|
|
|
|
layout_cols = (layout_screen_width + DESKTOP_SNAP_X - 1) / DESKTOP_SNAP_X;
|
|
|
|
layout_rows = (layout_screen_height + DESKTOP_SNAP_Y - 1) / DESKTOP_SNAP_Y;
|
1998-11-03 04:32:38 +03:00
|
|
|
layout_slots = g_new0 (struct layout_slot, layout_cols * layout_rows);
|
1998-10-30 03:47:54 +03:00
|
|
|
}
|
|
|
|
|
1998-12-17 07:51:24 +03:00
|
|
|
static void
|
|
|
|
setup_trashcan (char *desktop_dir)
|
|
|
|
{
|
|
|
|
char *trashcan_dir;
|
|
|
|
char *trash_pix;
|
|
|
|
|
|
|
|
trashcan_dir = g_concat_dir_and_file (desktop_directory, _("Trashcan"));
|
|
|
|
trash_pix = g_concat_dir_and_file (ICONDIR, "trash.xpm");
|
|
|
|
|
|
|
|
if (!g_file_exists (trashcan_dir)){
|
|
|
|
mkdir (trashcan_dir, 0777);
|
|
|
|
gnome_metadata_set (
|
|
|
|
trashcan_dir, "icon-filename", strlen (trash_pix)+1, trash_pix);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (trashcan_dir);
|
|
|
|
g_free (trash_pix);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that the user's desktop directory exists, and if not, create
|
|
|
|
* the default desktop setup.
|
1998-10-30 03:47:54 +03:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
create_desktop_dir (void)
|
|
|
|
{
|
|
|
|
char *home_link_name;
|
|
|
|
|
|
|
|
desktop_directory = g_concat_dir_and_file (gnome_user_home_dir, DESKTOP_DIR_NAME);
|
|
|
|
|
|
|
|
if (!g_file_exists (desktop_directory)) {
|
|
|
|
/* Create the directory */
|
|
|
|
|
|
|
|
mkdir (desktop_directory, 0777);
|
|
|
|
|
|
|
|
/* Create the link to the user's home directory so that he will have an icon */
|
|
|
|
home_link_name = g_concat_dir_and_file (desktop_directory, _("Home directory"));
|
|
|
|
|
|
|
|
if (mc_symlink (gnome_user_home_dir, home_link_name) != 0) {
|
|
|
|
message (FALSE,
|
|
|
|
_("Warning"),
|
|
|
|
_("Could not symlink %s to %s; will not have initial desktop icons."),
|
|
|
|
gnome_user_home_dir, home_link_name);
|
|
|
|
}
|
|
|
|
g_free (home_link_name);
|
|
|
|
}
|
1998-12-17 07:51:24 +03:00
|
|
|
|
1998-12-30 05:51:01 +03:00
|
|
|
/* setup_trashcan (desktop_directory); */
|
1998-10-30 03:47:54 +03:00
|
|
|
}
|
|
|
|
|
1998-12-03 02:37:27 +03:00
|
|
|
/* Sets up a proxy window for DnD on the specified X window. Courtesy of Owen Taylor */
|
|
|
|
static gboolean
|
|
|
|
setup_xdnd_proxy (guint32 xid, GdkWindow *proxy_window)
|
|
|
|
{
|
|
|
|
GdkAtom xdnd_proxy_atom;
|
|
|
|
guint32 proxy_xid;
|
|
|
|
Atom type;
|
|
|
|
int format;
|
|
|
|
unsigned long nitems, after;
|
|
|
|
Window *proxy_data;
|
|
|
|
Window proxy;
|
|
|
|
guint32 old_warnings;
|
|
|
|
|
|
|
|
XGrabServer (GDK_DISPLAY ());
|
|
|
|
|
|
|
|
xdnd_proxy_atom = gdk_atom_intern ("XdndProxy", FALSE);
|
|
|
|
proxy_xid = GDK_WINDOW_XWINDOW (proxy_window);
|
|
|
|
type = None;
|
|
|
|
proxy = None;
|
|
|
|
|
|
|
|
old_warnings = gdk_error_warnings;
|
|
|
|
|
|
|
|
gdk_error_code = 0;
|
|
|
|
gdk_error_warnings = 0;
|
|
|
|
|
|
|
|
/* Check if somebody else already owns drops on the root window */
|
|
|
|
|
|
|
|
XGetWindowProperty (GDK_DISPLAY (), xid,
|
|
|
|
xdnd_proxy_atom, 0,
|
|
|
|
1, False, AnyPropertyType,
|
|
|
|
&type, &format, &nitems, &after,
|
|
|
|
(guchar **) &proxy_data);
|
|
|
|
|
|
|
|
if (type != None) {
|
1998-12-11 05:05:19 +03:00
|
|
|
if (format == 32 && nitems == 1)
|
1998-12-03 02:37:27 +03:00
|
|
|
proxy = *proxy_data;
|
|
|
|
|
|
|
|
XFree (proxy_data);
|
|
|
|
}
|
|
|
|
|
1998-12-11 05:05:19 +03:00
|
|
|
/* The property was set, now check if the window it points to exists and
|
|
|
|
* has a XdndProxy property pointing to itself.
|
1998-12-03 02:37:27 +03:00
|
|
|
*/
|
|
|
|
if (proxy) {
|
|
|
|
XGetWindowProperty (GDK_DISPLAY (), proxy,
|
|
|
|
xdnd_proxy_atom, 0,
|
|
|
|
1, False, AnyPropertyType,
|
|
|
|
&type, &format, &nitems, &after,
|
|
|
|
(guchar **) &proxy_data);
|
|
|
|
|
|
|
|
if (!gdk_error_code && type != None) {
|
1998-12-11 05:05:19 +03:00
|
|
|
if (format == 32 && nitems == 1)
|
1998-12-03 02:37:27 +03:00
|
|
|
if (*proxy_data != proxy)
|
|
|
|
proxy = GDK_NONE;
|
|
|
|
|
|
|
|
XFree (proxy_data);
|
|
|
|
} else
|
|
|
|
proxy = GDK_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!proxy) {
|
|
|
|
/* OK, we can set the property to point to us */
|
|
|
|
|
|
|
|
XChangeProperty (GDK_DISPLAY (), xid,
|
|
|
|
xdnd_proxy_atom, gdk_atom_intern ("WINDOW", FALSE),
|
|
|
|
32, PropModeReplace,
|
|
|
|
(guchar *) &proxy_xid, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
gdk_error_code = 0;
|
|
|
|
gdk_error_warnings = old_warnings;
|
|
|
|
|
|
|
|
XUngrabServer (GDK_DISPLAY ());
|
1998-12-11 15:59:47 +03:00
|
|
|
gdk_flush ();
|
1998-12-03 02:37:27 +03:00
|
|
|
|
|
|
|
if (!proxy) {
|
|
|
|
/* Mark our window as a valid proxy window with a XdndProxy
|
|
|
|
* property pointing recursively;
|
|
|
|
*/
|
|
|
|
XChangeProperty (GDK_DISPLAY (), proxy_xid,
|
|
|
|
xdnd_proxy_atom, gdk_atom_intern ("WINDOW", FALSE),
|
|
|
|
32, PropModeReplace,
|
|
|
|
(guchar *) &proxy_xid, 1);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
} else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1998-12-07 18:47:00 +03:00
|
|
|
/* Returns the desktop icon that started the drag from the specified context */
|
1998-12-31 04:43:11 +03:00
|
|
|
static DesktopIconInfo *
|
1998-12-07 18:47:00 +03:00
|
|
|
find_icon_by_drag_context (GdkDragContext *context)
|
|
|
|
{
|
|
|
|
GtkWidget *source;
|
|
|
|
int i;
|
|
|
|
GList *l;
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *dii;
|
1998-12-07 18:47:00 +03:00
|
|
|
|
|
|
|
source = gtk_drag_get_source_widget (context);
|
|
|
|
if (!source)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
source = gtk_widget_get_toplevel (source);
|
|
|
|
|
|
|
|
for (i = 0; i < (layout_cols * layout_rows); i++)
|
|
|
|
for (l = layout_slots[i].icons; l; l = l->next) {
|
|
|
|
dii = l->data;
|
|
|
|
|
|
|
|
if (dii->dicon == source)
|
|
|
|
return dii;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1998-12-17 07:51:24 +03:00
|
|
|
/*
|
|
|
|
* Performs a drop of desktop icons onto the desktop. It basically moves the icons from their
|
1998-12-07 18:47:00 +03:00
|
|
|
* original position to the new coordinates.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
drop_desktop_icons (GdkDragContext *context, GtkSelectionData *data, int x, int y)
|
|
|
|
{
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *source_dii, *dii;
|
1998-12-07 18:47:00 +03:00
|
|
|
int dx, dy;
|
|
|
|
int i;
|
|
|
|
GList *l;
|
|
|
|
GSList *sel_icons, *sl;
|
|
|
|
|
1998-12-08 00:07:27 +03:00
|
|
|
/* FIXME: this needs to do the right thing (what Windows does) when desktop_auto_placement
|
|
|
|
* is enabled.
|
|
|
|
*/
|
|
|
|
|
1998-12-07 18:47:00 +03:00
|
|
|
/* Find the icon that the user is dragging */
|
|
|
|
|
|
|
|
source_dii = find_icon_by_drag_context (context);
|
|
|
|
if (!source_dii) {
|
|
|
|
g_warning ("Eeeeek, could not find the icon that started the drag!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute the distance to move icons */
|
|
|
|
|
1998-12-08 00:07:27 +03:00
|
|
|
if (desktop_snap_icons)
|
|
|
|
get_icon_snap_pos (&x, &y);
|
|
|
|
|
|
|
|
dx = x - source_dii->x - dnd_press_x;
|
|
|
|
dy = y - source_dii->y - dnd_press_y;
|
1998-12-07 18:47:00 +03:00
|
|
|
|
|
|
|
/* Build a list of selected icons */
|
|
|
|
|
|
|
|
sel_icons = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < (layout_cols * layout_rows); i++)
|
|
|
|
for (l = layout_slots[i].icons; l; l = l->next) {
|
|
|
|
dii = l->data;
|
|
|
|
if (dii->selected)
|
|
|
|
sel_icons = g_slist_prepend (sel_icons, l->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move the icons */
|
|
|
|
|
|
|
|
for (sl = sel_icons; sl; sl = sl->next) {
|
|
|
|
dii = sl->data;
|
|
|
|
desktop_icon_info_place (dii, FALSE, dii->x + dx, dii->y + dy);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clean up */
|
|
|
|
|
|
|
|
g_slist_free (sel_icons);
|
|
|
|
}
|
|
|
|
|
1998-12-03 02:37:27 +03:00
|
|
|
/* Callback used when the root window receives a drop */
|
1998-12-03 19:11:01 +03:00
|
|
|
static void
|
1998-12-08 04:31:17 +03:00
|
|
|
desktop_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y,
|
|
|
|
GtkSelectionData *data, guint info, guint time, gpointer user_data)
|
1998-12-03 02:37:27 +03:00
|
|
|
{
|
1998-12-04 05:08:06 +03:00
|
|
|
int retval;
|
|
|
|
gint dx, dy;
|
|
|
|
|
1998-12-08 00:07:27 +03:00
|
|
|
/* Fix the proxy window offsets */
|
|
|
|
|
|
|
|
gdk_window_get_position (widget->window, &dx, &dy);
|
|
|
|
x += dx;
|
|
|
|
y += dy;
|
|
|
|
|
1998-12-03 02:37:27 +03:00
|
|
|
switch (info) {
|
1998-12-05 04:01:13 +03:00
|
|
|
case TARGET_MC_DESKTOP_ICON:
|
1998-12-07 18:47:00 +03:00
|
|
|
drop_desktop_icons (context, data, x, y);
|
1998-12-05 04:01:13 +03:00
|
|
|
break;
|
|
|
|
|
1998-12-03 02:37:27 +03:00
|
|
|
case TARGET_URI_LIST:
|
1998-12-04 05:08:06 +03:00
|
|
|
retval = gdnd_drop_on_directory (context, data, desktop_directory);
|
|
|
|
if (retval)
|
|
|
|
reload_desktop_icons (TRUE, x, y);
|
1998-12-03 02:37:27 +03:00
|
|
|
|
1998-12-07 18:47:00 +03:00
|
|
|
break;
|
1998-12-03 02:37:27 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets up drag and drop to the desktop root window */
|
|
|
|
static void
|
|
|
|
setup_desktop_dnd (void)
|
|
|
|
{
|
|
|
|
dnd_proxy_window = gtk_invisible_new ();
|
|
|
|
gtk_widget_show (dnd_proxy_window);
|
|
|
|
|
|
|
|
if (!setup_xdnd_proxy (GDK_ROOT_WINDOW (), dnd_proxy_window->window))
|
1998-12-17 07:51:24 +03:00
|
|
|
g_warning ("There is already a process taking drop windows on the desktop\n");
|
1998-12-03 02:37:27 +03:00
|
|
|
|
|
|
|
gtk_drag_dest_set (dnd_proxy_window,
|
1998-12-04 05:08:06 +03:00
|
|
|
GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
|
1998-12-08 04:31:17 +03:00
|
|
|
dnd_desktop_targets,
|
|
|
|
dnd_desktop_ntargets,
|
1998-12-04 05:08:06 +03:00
|
|
|
GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_ASK);
|
1998-12-03 02:37:27 +03:00
|
|
|
|
|
|
|
gtk_signal_connect (GTK_OBJECT (dnd_proxy_window), "drag_data_received",
|
1998-12-08 04:31:17 +03:00
|
|
|
GTK_SIGNAL_FUNC (desktop_drag_data_received),
|
|
|
|
NULL);
|
1998-12-03 02:37:27 +03:00
|
|
|
}
|
|
|
|
|
1998-12-11 05:05:19 +03:00
|
|
|
/* Looks for the proxy window to get root window clicks from the window manager */
|
|
|
|
static GdkWindow *
|
|
|
|
find_click_proxy_window (void)
|
|
|
|
{
|
|
|
|
GdkAtom click_proxy_atom;
|
|
|
|
Atom type;
|
|
|
|
int format;
|
|
|
|
unsigned long nitems, after;
|
|
|
|
Window *proxy_data;
|
|
|
|
Window proxy;
|
|
|
|
guint32 old_warnings;
|
|
|
|
GdkWindow *proxy_gdk_window;
|
|
|
|
|
|
|
|
XGrabServer (GDK_DISPLAY ());
|
|
|
|
|
|
|
|
click_proxy_atom = gdk_atom_intern ("_WIN_DESKTOP_BUTTON_PROXY", FALSE);
|
|
|
|
type = None;
|
|
|
|
proxy = None;
|
|
|
|
|
|
|
|
old_warnings = gdk_error_warnings;
|
|
|
|
|
|
|
|
gdk_error_code = 0;
|
|
|
|
gdk_error_warnings = 0;
|
|
|
|
|
|
|
|
/* Check if the proxy window exists */
|
|
|
|
|
|
|
|
XGetWindowProperty (GDK_DISPLAY (), GDK_ROOT_WINDOW (),
|
|
|
|
click_proxy_atom, 0,
|
|
|
|
1, False, AnyPropertyType,
|
|
|
|
&type, &format, &nitems, &after,
|
|
|
|
(guchar **) &proxy_data);
|
|
|
|
|
|
|
|
if (type != None) {
|
|
|
|
if (format == 32 && nitems == 1)
|
|
|
|
proxy = *proxy_data;
|
|
|
|
|
|
|
|
XFree (proxy_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The property was set, now check if the window it points to exists and
|
|
|
|
* has a _WIN_DESKTOP_BUTTON_PROXY property pointing to itself.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (proxy) {
|
|
|
|
XGetWindowProperty (GDK_DISPLAY (), proxy,
|
|
|
|
click_proxy_atom, 0,
|
|
|
|
1, False, AnyPropertyType,
|
|
|
|
&type, &format, &nitems, &after,
|
|
|
|
(guchar **) &proxy_data);
|
|
|
|
|
|
|
|
if (!gdk_error_code && type != None) {
|
|
|
|
if (format == 32 && nitems == 1)
|
|
|
|
if (*proxy_data != proxy)
|
|
|
|
proxy = GDK_NONE;
|
|
|
|
|
|
|
|
XFree (proxy_data);
|
|
|
|
} else
|
|
|
|
proxy = GDK_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gdk_error_code = 0;
|
|
|
|
gdk_error_warnings = old_warnings;
|
|
|
|
|
|
|
|
XUngrabServer (GDK_DISPLAY ());
|
1998-12-11 15:59:47 +03:00
|
|
|
gdk_flush ();
|
1998-12-11 05:05:19 +03:00
|
|
|
|
|
|
|
if (proxy)
|
|
|
|
proxy_gdk_window = gdk_window_foreign_new (proxy);
|
|
|
|
else
|
|
|
|
proxy_gdk_window = NULL;
|
|
|
|
|
|
|
|
return proxy_gdk_window;
|
|
|
|
}
|
|
|
|
|
1998-12-11 15:59:47 +03:00
|
|
|
/* Executes the popup menu for the desktop */
|
|
|
|
static void
|
|
|
|
desktop_popup (GdkEventButton *event)
|
|
|
|
{
|
|
|
|
printf ("FIXME: display desktop popup menu\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draws the rubberband rectangle for selecting icons on the desktop */
|
|
|
|
static void
|
|
|
|
draw_rubberband (int x, int y)
|
|
|
|
{
|
|
|
|
int x1, y1, x2, y2;
|
|
|
|
|
|
|
|
if (click_start_x < x) {
|
|
|
|
x1 = click_start_x;
|
|
|
|
x2 = x;
|
|
|
|
} else {
|
|
|
|
x1 = x;
|
|
|
|
x2 = click_start_x;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (click_start_y < y) {
|
|
|
|
y1 = click_start_y;
|
|
|
|
y2 = y;
|
|
|
|
} else {
|
|
|
|
y1 = y;
|
|
|
|
y2 = click_start_y;
|
|
|
|
}
|
|
|
|
|
|
|
|
gdk_draw_rectangle (GDK_ROOT_PARENT (), click_gc, FALSE, x1, y1, x2 - x1, y2 - y1);
|
|
|
|
}
|
|
|
|
|
1998-12-17 07:51:24 +03:00
|
|
|
/*
|
|
|
|
* Stores dii->selected into dii->tmp_selected to keep the original selection
|
1998-12-11 15:59:47 +03:00
|
|
|
* around while the user is rubberbanding.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
store_temp_selection (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
GList *l;
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *dii;
|
1998-12-11 15:59:47 +03:00
|
|
|
|
|
|
|
for (i = 0; i < (layout_cols * layout_rows); i++)
|
|
|
|
for (l = layout_slots[i].icons; l; l = l->next) {
|
|
|
|
dii = l->data;
|
|
|
|
|
|
|
|
dii->tmp_selected = dii->selected;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-17 07:51:24 +03:00
|
|
|
/**
|
|
|
|
* icon_is_in_area:
|
|
|
|
* @dii: the desktop icon information
|
|
|
|
*
|
|
|
|
* Returns TRUE if the specified icon is at least partially inside the specified
|
1998-12-11 15:59:47 +03:00
|
|
|
* area, or FALSE otherwise.
|
|
|
|
*/
|
|
|
|
static int
|
1998-12-31 04:43:11 +03:00
|
|
|
icon_is_in_area (DesktopIconInfo *dii, int x1, int y1, int x2, int y2)
|
1998-12-11 15:59:47 +03:00
|
|
|
{
|
|
|
|
DesktopIcon *dicon;
|
|
|
|
|
|
|
|
dicon = DESKTOP_ICON (dii->dicon);
|
|
|
|
|
|
|
|
/* FIXME: this only intersects the rectangle with the icon image's
|
|
|
|
* bounds. Doing the "hard" intersection with the actual shape of the
|
|
|
|
* image is left as an exercise to the reader.
|
|
|
|
*/
|
|
|
|
|
|
|
|
x1 -= dii->x;
|
|
|
|
y1 -= dii->y;
|
|
|
|
x2 -= dii->x;
|
|
|
|
y2 -= dii->y;
|
|
|
|
|
|
|
|
if (x1 < dicon->icon_x + dicon->icon_w - 1
|
|
|
|
&& x2 > dicon->icon_x
|
|
|
|
&& y1 < dicon->icon_y + dicon->icon_h - 1
|
|
|
|
&& y2 > dicon->icon_y)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (x1 < dicon->text_x + dicon->text_w - 1
|
|
|
|
&& x2 > dicon->text_x
|
|
|
|
&& y1 < dicon->text_y + dicon->text_h - 1
|
|
|
|
&& y2 > dicon->text_y)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the selection being rubberbanded. It selects or unselects the icons
|
|
|
|
* as appropriate.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
update_drag_selection (int x, int y)
|
|
|
|
{
|
|
|
|
int x1, y1, x2, y2;
|
|
|
|
int i;
|
|
|
|
GList *l;
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *dii;
|
1998-12-11 15:59:47 +03:00
|
|
|
int additive, invert, in_area;
|
|
|
|
|
|
|
|
if (click_start_x < x) {
|
|
|
|
x1 = click_start_x;
|
|
|
|
x2 = x;
|
|
|
|
} else {
|
|
|
|
x1 = x;
|
|
|
|
x2 = click_start_x;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (click_start_y < y) {
|
|
|
|
y1 = click_start_y;
|
|
|
|
y2 = y;
|
|
|
|
} else {
|
|
|
|
y1 = y;
|
|
|
|
y2 = click_start_y;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Select or unselect icons as appropriate */
|
|
|
|
|
|
|
|
additive = click_start_state & GDK_SHIFT_MASK;
|
|
|
|
invert = click_start_state & GDK_CONTROL_MASK;
|
|
|
|
|
|
|
|
for (i = 0; i < (layout_cols * layout_rows); i++)
|
|
|
|
for (l = layout_slots[i].icons; l; l = l->next) {
|
|
|
|
dii = l->data;
|
|
|
|
|
|
|
|
in_area = icon_is_in_area (dii, x1, y1, x2, y2);
|
|
|
|
|
|
|
|
if (in_area) {
|
|
|
|
if (invert) {
|
|
|
|
if (dii->selected == dii->tmp_selected) {
|
|
|
|
desktop_icon_select (DESKTOP_ICON (dii->dicon), !dii->selected);
|
|
|
|
dii->selected = !dii->selected;
|
|
|
|
}
|
|
|
|
} else if (additive) {
|
|
|
|
if (!dii->selected) {
|
|
|
|
desktop_icon_select (DESKTOP_ICON (dii->dicon), TRUE);
|
|
|
|
dii->selected = TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!dii->selected) {
|
|
|
|
desktop_icon_select (DESKTOP_ICON (dii->dicon), TRUE);
|
|
|
|
dii->selected = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (dii->selected != dii->tmp_selected) {
|
|
|
|
desktop_icon_select (DESKTOP_ICON (dii->dicon), dii->tmp_selected);
|
|
|
|
dii->selected = dii->tmp_selected;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handles button presses on the root window via the click_proxy_gdk_window */
|
1998-12-11 05:05:19 +03:00
|
|
|
static gint
|
1998-12-11 15:59:47 +03:00
|
|
|
click_proxy_button_press (GtkWidget *widget, GdkEventButton *event, gpointer data)
|
1998-12-11 05:05:19 +03:00
|
|
|
{
|
1998-12-11 18:20:25 +03:00
|
|
|
GdkCursor *cursor;
|
|
|
|
|
1998-12-11 15:59:47 +03:00
|
|
|
if (event->button == 1) {
|
|
|
|
click_start_x = event->x;
|
|
|
|
click_start_y = event->y;
|
|
|
|
click_start_state = event->state;
|
|
|
|
|
|
|
|
XGrabServer (GDK_DISPLAY ());
|
|
|
|
|
1998-12-11 18:20:25 +03:00
|
|
|
cursor = gdk_cursor_new (GDK_TOP_LEFT_ARROW);
|
1998-12-11 15:59:47 +03:00
|
|
|
gdk_pointer_grab (GDK_ROOT_PARENT (),
|
|
|
|
FALSE,
|
|
|
|
GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK,
|
|
|
|
NULL,
|
1998-12-11 18:20:25 +03:00
|
|
|
cursor,
|
1998-12-11 15:59:47 +03:00
|
|
|
event->time);
|
1998-12-11 18:20:25 +03:00
|
|
|
gdk_cursor_destroy (cursor);
|
1998-12-11 15:59:47 +03:00
|
|
|
|
|
|
|
/* If no modifiers are pressed, we unselect all the icons */
|
|
|
|
|
|
|
|
if ((click_start_state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK)) == 0)
|
|
|
|
unselect_all (NULL);
|
|
|
|
|
|
|
|
store_temp_selection (); /* Save the original selection */
|
|
|
|
|
|
|
|
draw_rubberband (event->x, event->y);
|
|
|
|
click_current_x = event->x;
|
|
|
|
click_current_y = event->y;
|
|
|
|
click_dragging = TRUE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
} else if (event->button == 3) {
|
|
|
|
desktop_popup (event);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1998-12-11 05:05:19 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1998-12-11 15:59:47 +03:00
|
|
|
/* Handles button releases on the root window via the click_proxy_gdk_window */
|
|
|
|
static gint
|
|
|
|
click_proxy_button_release (GtkWidget *widget, GdkEventButton *event, gpointer data)
|
|
|
|
{
|
|
|
|
if (!click_dragging || event->button != 1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
draw_rubberband (click_current_x, click_current_y);
|
|
|
|
gdk_pointer_ungrab (event->time);
|
|
|
|
click_dragging = FALSE;
|
|
|
|
|
|
|
|
update_drag_selection (event->x, event->y);
|
|
|
|
|
|
|
|
XUngrabServer (GDK_DISPLAY ());
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handles motion events when dragging the icon-selection rubberband on the desktop */
|
|
|
|
static gint
|
|
|
|
click_proxy_motion (GtkWidget *widget, GdkEventMotion *event, gpointer data)
|
|
|
|
{
|
|
|
|
if (!click_dragging)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
draw_rubberband (click_current_x, click_current_y);
|
|
|
|
draw_rubberband (event->x, event->y);
|
|
|
|
update_drag_selection (event->x, event->y);
|
|
|
|
click_current_x = event->x;
|
|
|
|
click_current_y = event->y;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1998-12-17 07:51:24 +03:00
|
|
|
/*
|
|
|
|
* Filter that translates proxied events from virtual root windows into normal
|
1998-12-11 15:59:47 +03:00
|
|
|
* Gdk events for the click_proxy_invisible widget.
|
|
|
|
*/
|
|
|
|
static GdkFilterReturn
|
|
|
|
click_proxy_filter (GdkXEvent *xevent, GdkEvent *event, gpointer data)
|
|
|
|
{
|
|
|
|
XEvent *xev;
|
|
|
|
|
|
|
|
xev = xevent;
|
|
|
|
|
|
|
|
switch (xev->type) {
|
|
|
|
case ButtonPress:
|
|
|
|
case ButtonRelease:
|
1998-12-11 18:20:25 +03:00
|
|
|
/* Translate button events into events that come from the proxy
|
|
|
|
* window, so that we can catch them as a signal from the
|
|
|
|
* invisible widget.
|
|
|
|
*/
|
1998-12-11 15:59:47 +03:00
|
|
|
if (xev->type == ButtonPress)
|
|
|
|
event->button.type = GDK_BUTTON_PRESS;
|
|
|
|
else
|
|
|
|
event->button.type = GDK_BUTTON_RELEASE;
|
|
|
|
|
|
|
|
gdk_window_ref (click_proxy_gdk_window);
|
|
|
|
|
|
|
|
event->button.window = click_proxy_gdk_window;
|
|
|
|
event->button.send_event = xev->xbutton.send_event;
|
|
|
|
event->button.time = xev->xbutton.time;
|
|
|
|
event->button.x = xev->xbutton.x;
|
|
|
|
event->button.y = xev->xbutton.y;
|
|
|
|
event->button.state = xev->xbutton.state;
|
|
|
|
event->button.button = xev->xbutton.button;
|
1998-12-11 18:20:25 +03:00
|
|
|
|
|
|
|
return GDK_FILTER_TRANSLATE;
|
|
|
|
|
|
|
|
case DestroyNotify:
|
|
|
|
/* The proxy window was destroyed (i.e. the window manager
|
|
|
|
* died), so we have to cope with it
|
|
|
|
*/
|
1998-12-11 18:39:59 +03:00
|
|
|
if (((GdkEventAny *) event)->window == click_proxy_gdk_window) {
|
|
|
|
gdk_window_destroy_notify (click_proxy_gdk_window);
|
|
|
|
click_proxy_gdk_window = NULL;
|
|
|
|
}
|
1998-12-11 18:20:25 +03:00
|
|
|
|
|
|
|
return GDK_FILTER_REMOVE;
|
1998-12-11 15:59:47 +03:00
|
|
|
|
|
|
|
default:
|
1998-12-11 18:20:25 +03:00
|
|
|
break;
|
1998-12-11 15:59:47 +03:00
|
|
|
}
|
|
|
|
|
1998-12-11 18:20:25 +03:00
|
|
|
return GDK_FILTER_CONTINUE;
|
|
|
|
}
|
|
|
|
|
1998-12-17 07:51:24 +03:00
|
|
|
/*
|
|
|
|
* Creates a proxy window to receive clicks from the root window and
|
|
|
|
* sets up the necessary event filters.
|
1998-12-11 18:20:25 +03:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
setup_desktop_click_proxy_window (void)
|
|
|
|
{
|
|
|
|
click_proxy_gdk_window = find_click_proxy_window ();
|
|
|
|
if (!click_proxy_gdk_window) {
|
|
|
|
g_warning ("Root window clicks will not work as no GNOME-compliant window manager could be found!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make the proxy window send events to the invisible proxy widget */
|
|
|
|
gdk_window_set_user_data (click_proxy_gdk_window, click_proxy_invisible);
|
|
|
|
|
|
|
|
/* Add our filter to get events */
|
|
|
|
gdk_window_add_filter (click_proxy_gdk_window, click_proxy_filter, NULL);
|
|
|
|
|
1998-12-17 07:51:24 +03:00
|
|
|
/*
|
|
|
|
* The proxy window for clicks sends us button press events with
|
1998-12-11 18:20:25 +03:00
|
|
|
* SubstructureNotifyMask. We need StructureNotifyMask to receive
|
|
|
|
* DestroyNotify events, too.
|
|
|
|
*/
|
|
|
|
|
|
|
|
XSelectInput (GDK_DISPLAY (), GDK_WINDOW_XWINDOW (click_proxy_gdk_window),
|
|
|
|
SubstructureNotifyMask | StructureNotifyMask);
|
|
|
|
}
|
|
|
|
|
1998-12-17 07:51:24 +03:00
|
|
|
/*
|
|
|
|
* Handler for PropertyNotify events from the root window; it must change the
|
1998-12-11 18:20:25 +03:00
|
|
|
* proxy window to a new one.
|
|
|
|
*/
|
|
|
|
static gint
|
|
|
|
click_proxy_property_notify (GtkWidget *widget, GdkEventProperty *event, gpointer data)
|
|
|
|
{
|
|
|
|
if (event->window != GDK_ROOT_PARENT ())
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (event->atom != gdk_atom_intern ("_WIN_DESKTOP_BUTTON_PROXY", FALSE))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* If there already is a proxy window, destroy it */
|
|
|
|
|
|
|
|
click_proxy_gdk_window = NULL;
|
|
|
|
|
|
|
|
/* Get the new proxy window */
|
|
|
|
|
|
|
|
setup_desktop_click_proxy_window ();
|
|
|
|
|
|
|
|
return TRUE;
|
1998-12-11 15:59:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#define gray50_width 2
|
|
|
|
#define gray50_height 2
|
|
|
|
static char gray50_bits[] = {
|
|
|
|
0x02, 0x01, };
|
|
|
|
|
1998-12-11 05:05:19 +03:00
|
|
|
/* Sets up the window manager proxy window to receive clicks on the desktop root window */
|
|
|
|
static void
|
|
|
|
setup_desktop_clicks (void)
|
|
|
|
{
|
1998-12-11 15:59:47 +03:00
|
|
|
GdkColormap *cmap;
|
|
|
|
GdkColor color;
|
|
|
|
GdkBitmap *stipple;
|
|
|
|
|
1998-12-11 05:05:19 +03:00
|
|
|
click_proxy_invisible = gtk_invisible_new ();
|
|
|
|
gtk_widget_show (click_proxy_invisible);
|
1998-12-11 15:59:47 +03:00
|
|
|
|
1998-12-11 18:20:25 +03:00
|
|
|
/* Make the root window send events to the invisible proxy widget */
|
1998-12-11 15:59:47 +03:00
|
|
|
gdk_window_set_user_data (GDK_ROOT_PARENT (), click_proxy_invisible);
|
|
|
|
|
1998-12-11 18:20:25 +03:00
|
|
|
/* Add our filter to get button press/release events (they are sent by
|
|
|
|
* the WM * with the window set to the root). Our filter will translate
|
|
|
|
* them to a GdkEvent with the proxy window as its window field.
|
|
|
|
*/
|
1998-12-11 15:59:47 +03:00
|
|
|
gdk_window_add_filter (GDK_ROOT_PARENT (), click_proxy_filter, NULL);
|
1998-12-11 05:05:19 +03:00
|
|
|
|
1998-12-11 18:20:25 +03:00
|
|
|
/* Select for PropertyNotify events from the root window */
|
|
|
|
|
|
|
|
XSelectInput (GDK_DISPLAY (), GDK_ROOT_WINDOW (), PropertyChangeMask);
|
1998-12-11 06:18:41 +03:00
|
|
|
|
1998-12-11 18:20:25 +03:00
|
|
|
/* Create the proxy window for clicks on the root window */
|
|
|
|
setup_desktop_click_proxy_window ();
|
|
|
|
|
|
|
|
/* Connect the signals */
|
1998-12-11 06:18:41 +03:00
|
|
|
|
1998-12-11 15:59:47 +03:00
|
|
|
gtk_signal_connect (GTK_OBJECT (click_proxy_invisible), "button_press_event",
|
|
|
|
(GtkSignalFunc) click_proxy_button_press,
|
|
|
|
NULL);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (click_proxy_invisible), "button_release_event",
|
|
|
|
(GtkSignalFunc) click_proxy_button_release,
|
1998-12-11 05:05:19 +03:00
|
|
|
NULL);
|
1998-12-11 15:59:47 +03:00
|
|
|
gtk_signal_connect (GTK_OBJECT (click_proxy_invisible), "motion_notify_event",
|
|
|
|
(GtkSignalFunc) click_proxy_motion,
|
|
|
|
NULL);
|
|
|
|
|
1998-12-11 18:20:25 +03:00
|
|
|
gtk_signal_connect (GTK_OBJECT (click_proxy_invisible), "property_notify_event",
|
|
|
|
(GtkSignalFunc) click_proxy_property_notify,
|
|
|
|
NULL);
|
|
|
|
|
1998-12-11 15:59:47 +03:00
|
|
|
/* Create the GC to paint the rubberband rectangle */
|
|
|
|
|
|
|
|
click_gc = gdk_gc_new (GDK_ROOT_PARENT ());
|
|
|
|
|
|
|
|
cmap = gdk_window_get_colormap (GDK_ROOT_PARENT ());
|
|
|
|
|
|
|
|
gdk_color_white (cmap, &color);
|
|
|
|
if (color.pixel == 0)
|
|
|
|
gdk_color_black (cmap, &color);
|
|
|
|
|
|
|
|
gdk_gc_set_foreground (click_gc, &color);
|
|
|
|
gdk_gc_set_function (click_gc, GDK_XOR);
|
|
|
|
|
|
|
|
gdk_gc_set_fill (click_gc, GDK_STIPPLED);
|
|
|
|
|
|
|
|
stipple = gdk_bitmap_create_from_data (NULL, gray50_bits, gray50_width, gray50_height);
|
|
|
|
gdk_gc_set_stipple (click_gc, stipple);
|
|
|
|
gdk_bitmap_unref (stipple);
|
1998-12-11 05:05:19 +03:00
|
|
|
}
|
|
|
|
|
1998-10-30 03:47:54 +03:00
|
|
|
/**
|
|
|
|
* desktop_init
|
|
|
|
*
|
|
|
|
* Initializes the desktop by setting up the default icons (if necessary), setting up drag and drop,
|
|
|
|
* and other miscellaneous tasks.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
desktop_init (void)
|
|
|
|
{
|
|
|
|
create_layout_info ();
|
|
|
|
create_desktop_dir ();
|
1998-12-04 05:08:06 +03:00
|
|
|
load_desktop_icons (FALSE, 0, 0);
|
1998-12-03 02:37:27 +03:00
|
|
|
setup_desktop_dnd ();
|
1998-12-11 05:05:19 +03:00
|
|
|
setup_desktop_clicks ();
|
1998-10-30 03:47:54 +03:00
|
|
|
}
|
|
|
|
|
1998-11-03 04:32:38 +03:00
|
|
|
/**
|
|
|
|
* desktop_destroy
|
1998-10-30 03:47:54 +03:00
|
|
|
*
|
|
|
|
* Shuts the desktop down by destroying the desktop icons.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
desktop_destroy (void)
|
|
|
|
{
|
|
|
|
/* Destroy the desktop icons */
|
|
|
|
|
1998-12-03 02:37:27 +03:00
|
|
|
destroy_desktop_icons ();
|
1998-10-30 03:47:54 +03:00
|
|
|
|
|
|
|
/* Cleanup */
|
|
|
|
|
|
|
|
g_free (layout_slots);
|
|
|
|
layout_slots = NULL;
|
|
|
|
layout_cols = 0;
|
|
|
|
layout_rows = 0;
|
|
|
|
|
|
|
|
g_free (desktop_directory);
|
|
|
|
desktop_directory = NULL;
|
1998-12-03 02:37:27 +03:00
|
|
|
|
|
|
|
/* Remove DnD crap */
|
|
|
|
|
|
|
|
gtk_widget_destroy (dnd_proxy_window);
|
|
|
|
XDeleteProperty (GDK_DISPLAY (), GDK_ROOT_WINDOW (), gdk_atom_intern ("XdndProxy", FALSE));
|
1998-12-11 18:20:25 +03:00
|
|
|
|
|
|
|
/* Remove click-on-desktop crap */
|
|
|
|
|
|
|
|
gdk_window_unref (click_proxy_gdk_window);
|
|
|
|
gtk_widget_destroy (click_proxy_invisible);
|
1998-10-30 03:47:54 +03:00
|
|
|
}
|