Skip to content

Commit 0948eec

Browse files
committed
metadata: Add back cached position values in NemoFile. Be sure to clear
the timestamp metadata on files being moved/copied to or from the desktop. This ensures the lazy flag operates correctly. With the desktop becoming a separate process, transfers that include position info need to be handled slightly differently, as the old way of just setting metadata and reacting to it from a new container won't work - the file gets debuted in the other process sooner than (or not reliably after, at least) the metadata is written, resulting in inconsistent positioning.
1 parent a765074 commit 0948eec

5 files changed

+97
-46
lines changed

libnemo-private/nemo-directory.c

+2-12
Original file line numberDiff line numberDiff line change
@@ -1412,24 +1412,14 @@ nemo_directory_schedule_position_set (GList *position_setting_list)
14121412
nemo_file_set_position (file, -1, -1);
14131413
}
14141414

1415-
if (item->set) {
1416-
nemo_file_set_time_metadata
1417-
(file,
1418-
NEMO_METADATA_KEY_ICON_POSITION_TIMESTAMP,
1419-
now);
1420-
} else {
1421-
nemo_file_set_time_metadata
1422-
(file,
1423-
NEMO_METADATA_KEY_ICON_POSITION_TIMESTAMP,
1424-
UNDEFINED_TIME);
1425-
}
1426-
14271415
if (item->set) {
14281416
nemo_file_set_monitor_number (file, item->monitor);
14291417
} else {
14301418
nemo_file_set_monitor_number (file, -1);
14311419
}
14321420

1421+
nemo_file_set_time_metadata (file, NEMO_METADATA_KEY_ICON_POSITION_TIMESTAMP, UNDEFINED_TIME);
1422+
14331423
nemo_file_unref (file);
14341424
}
14351425
}

libnemo-private/nemo-file-operations.c

+50-22
Original file line numberDiff line numberDiff line change
@@ -4195,7 +4195,7 @@ copy_move_file (CopyMoveJob *copy_job,
41954195
gboolean res;
41964196
int unique_name_nr;
41974197
gboolean handled_invalid_filename;
4198-
gboolean target_is_desktop;
4198+
gboolean target_is_desktop, source_is_desktop;
41994199

42004200
job = (CommonJob *)copy_job;
42014201

@@ -4207,6 +4207,17 @@ copy_move_file (CopyMoveJob *copy_job,
42074207
target_is_desktop = (copy_job->desktop_location != NULL &&
42084208
g_file_equal (copy_job->desktop_location, dest_dir));
42094209

4210+
source_is_desktop = FALSE;
4211+
4212+
if (src != NULL) {
4213+
GFile *parent = g_file_get_parent (src);
4214+
4215+
if (parent != NULL && g_file_equal (copy_job->desktop_location, parent)) {
4216+
source_is_desktop = TRUE;
4217+
g_object_unref (parent);
4218+
}
4219+
}
4220+
42104221
unique_name_nr = 1;
42114222

42124223
/* another file in the same directory might have handled the invalid
@@ -4328,13 +4339,11 @@ copy_move_file (CopyMoveJob *copy_job,
43284339
report_copy_progress (copy_job, source_info, transfer_info);
43294340

43304341
if (debuting_files) {
4331-
if (target_is_desktop) {
4332-
if (position) {
4333-
nemo_file_changes_queue_schedule_position_set (dest, *position, job->monitor_num);
4334-
} else {
4335-
nemo_file_changes_queue_schedule_position_remove (dest);
4336-
}
4337-
}
4342+
if (target_is_desktop && position) {
4343+
nemo_file_changes_queue_schedule_position_set (dest, *position, job->monitor_num);
4344+
} else if (source_is_desktop) {
4345+
nemo_file_changes_queue_schedule_position_remove (dest);
4346+
}
43384347

43394348
g_hash_table_replace (debuting_files, g_object_ref (dest), GINT_TO_POINTER (TRUE));
43404349
}
@@ -4915,11 +4924,22 @@ move_file_prepare (CopyMoveJob *move_job,
49154924
GFileCopyFlags flags;
49164925
MoveFileCopyFallback *fallback;
49174926
gboolean handled_invalid_filename;
4918-
gboolean target_is_desktop;
4927+
gboolean target_is_desktop, source_is_desktop;
49194928

49204929
target_is_desktop = (move_job->desktop_location != NULL &&
49214930
g_file_equal (move_job->desktop_location, dest_dir));
49224931

4932+
source_is_desktop = FALSE;
4933+
4934+
if (src != NULL) {
4935+
GFile *parent = g_file_get_parent (src);
4936+
4937+
if (parent != NULL && g_file_equal (move_job->desktop_location, parent)) {
4938+
source_is_desktop = TRUE;
4939+
g_object_unref (parent);
4940+
}
4941+
}
4942+
49234943
overwrite = FALSE;
49244944
handled_invalid_filename = *dest_fs_type != NULL;
49254945

@@ -4983,12 +5003,10 @@ move_file_prepare (CopyMoveJob *move_job,
49835003

49845004
nemo_file_changes_queue_file_moved (src, dest);
49855005

4986-
if (target_is_desktop) {
4987-
if (position) {
4988-
nemo_file_changes_queue_schedule_position_set (dest, *position, job->monitor_num);
4989-
} else {
4990-
nemo_file_changes_queue_schedule_position_remove (dest);
4991-
}
5006+
if (target_is_desktop && position) {
5007+
nemo_file_changes_queue_schedule_position_set (dest, *position, job->monitor_num);
5008+
} else if (source_is_desktop) {
5009+
nemo_file_changes_queue_schedule_position_remove (dest);
49925010
}
49935011

49945012
if (job->undo_info != NULL) {
@@ -5344,6 +5362,7 @@ nemo_file_operations_move (GList *files,
53445362

53455363
job = op_job_new (CopyMoveJob, parent_window);
53465364
job->is_move = TRUE;
5365+
job->desktop_location = nemo_get_desktop_location ();
53475366
job->done_callback = done_callback;
53485367
job->done_callback_data = done_callback_data;
53495368
job->files = eel_g_object_list_copy (files);
@@ -5442,11 +5461,22 @@ link_file (CopyMoveJob *job,
54425461
char *primary, *secondary, *details;
54435462
int response;
54445463
gboolean handled_invalid_filename;
5445-
gboolean target_is_desktop;
5464+
gboolean target_is_desktop, source_is_desktop;
54465465

54475466
target_is_desktop = (job->desktop_location != NULL &&
54485467
g_file_equal (job->desktop_location, dest_dir));
54495468

5469+
source_is_desktop = FALSE;
5470+
5471+
if (src != NULL) {
5472+
GFile *parent = g_file_get_parent (src);
5473+
5474+
if (parent != NULL && g_file_equal (job->desktop_location, parent)) {
5475+
source_is_desktop = TRUE;
5476+
g_object_unref (parent);
5477+
}
5478+
}
5479+
54505480
common = (CommonJob *)job;
54515481

54525482
count = 0;
@@ -5485,12 +5515,10 @@ link_file (CopyMoveJob *job,
54855515

54865516
nemo_file_changes_queue_file_added (dest);
54875517

5488-
if (target_is_desktop) {
5489-
if (position) {
5490-
nemo_file_changes_queue_schedule_position_set (dest, *position, common->monitor_num);
5491-
} else {
5492-
nemo_file_changes_queue_schedule_position_remove (dest);
5493-
}
5518+
if (target_is_desktop && position) {
5519+
nemo_file_changes_queue_schedule_position_set (dest, *position, common->monitor_num);
5520+
} else if (source_is_desktop) {
5521+
nemo_file_changes_queue_schedule_position_remove (dest);
54945522
}
54955523

54965524
g_object_unref (dest);

libnemo-private/nemo-file-private.h

+2
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ struct NemoFileDetails
221221
time_t free_space_read; /* The time free_space was updated, or 0 for never */
222222

223223
gint desktop_monitor;
224+
gint cached_position_x;
225+
gint cached_position_y;
224226
};
225227

226228
typedef struct {

libnemo-private/nemo-file.c

+25-12
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ nemo_file_init (NemoFile *file)
178178
file->details = G_TYPE_INSTANCE_GET_PRIVATE ((file), NEMO_TYPE_FILE, NemoFileDetails);
179179

180180
file->details->desktop_monitor = -1;
181+
file->details->cached_position_x = -1;
182+
file->details->cached_position_y = -1;
181183

182184
nemo_file_clear_info (file);
183185
nemo_file_invalidate_extension_info_internal (file);
@@ -7571,22 +7573,30 @@ nemo_file_get_position (NemoFile *file, GdkPoint *point)
75717573
{
75727574
gint x, y;
75737575

7574-
char *position_string;
7575-
gboolean position_good;
7576-
char c;
7576+
if (file->details->cached_position_x == -1) {
7577+
char *position_string;
7578+
gboolean position_good;
7579+
char c;
75777580

7578-
/* Get the current position of this icon from the metadata. */
7579-
position_string = nemo_file_get_metadata (file, NEMO_METADATA_KEY_ICON_POSITION, "");
7581+
/* Get the current position of this icon from the metadata. */
7582+
position_string = nemo_file_get_metadata (file, NEMO_METADATA_KEY_ICON_POSITION, "");
75807583

7581-
position_good = sscanf (position_string, " %d , %d %c", &x, &y, &c) == 2;
7582-
g_free (position_string);
7584+
position_good = sscanf (position_string, " %d , %d %c", &x, &y, &c) == 2;
7585+
g_free (position_string);
75837586

7584-
if (position_good) {
7585-
point->x = x;
7586-
point->y = y;
7587+
if (position_good) {
7588+
point->x = x;
7589+
point->y = y;
7590+
} else {
7591+
point->x = -1;
7592+
point->y = -1;
7593+
}
7594+
7595+
file->details->cached_position_x = x;
7596+
file->details->cached_position_y = y;
75877597
} else {
7588-
point->x = -1;
7589-
point->y = -1;
7598+
point->x = file->details->cached_position_x;
7599+
point->y = file->details->cached_position_y;
75907600
}
75917601
}
75927602

@@ -7602,6 +7612,9 @@ nemo_file_set_position (NemoFile *file, gint x, gint y)
76027612
}
76037613
nemo_file_set_metadata (file, NEMO_METADATA_KEY_ICON_POSITION, NULL, position_string);
76047614

7615+
file->details->cached_position_x = x;
7616+
file->details->cached_position_y = y;
7617+
76057618
g_free (position_string);
76067619
}
76077620

src/nemo-icon-view-grid-container.c

+18
Original file line numberDiff line numberDiff line change
@@ -901,13 +901,17 @@ nemo_icon_view_grid_container_update_icon (NemoIconContainer *container,
901901
gboolean embedded_text_needs_loading;
902902
gboolean has_open_window;
903903
gint scale_factor;
904+
EelIRect old_size, new_size;
905+
gint old_width, new_width;
904906

905907
if (icon == NULL) {
906908
return;
907909
}
908910

909911
details = container->details;
910912

913+
nemo_icon_canvas_item_get_icon_canvas_rectangle (icon->item, &old_size);
914+
911915
/* Get the appropriate images for the file. */
912916
icon_size = container->details->forced_icon_size;
913917

@@ -967,6 +971,20 @@ nemo_icon_view_grid_container_update_icon (NemoIconContainer *container,
967971
nemo_icon_canvas_item_set_image (icon->item, pixbuf);
968972
nemo_icon_canvas_item_set_attach_points (icon->item, attach_points, n_attach_points);
969973

974+
nemo_icon_canvas_item_get_icon_canvas_rectangle (icon->item, &new_size);
975+
976+
old_width = old_size.x1 - old_size.x0;
977+
new_width = new_size.x1 - new_size.x0;
978+
979+
if (old_width != 0 && old_width != new_width) {
980+
nemo_icon_container_request_update (container, icon->data);
981+
982+
icon->has_lazy_position = TRUE;
983+
container->details->new_icons = g_list_prepend (container->details->new_icons, icon);
984+
nemo_icon_container_redo_layout (container);
985+
nemo_icon_container_icon_raise (container, icon);
986+
}
987+
970988
/* Let the pixbufs go. */
971989
g_object_unref (pixbuf);
972990

0 commit comments

Comments
 (0)