Browse Source

Add setting of sel rect from gui cboard paste

master
cancel 5 years ago
parent
commit
af21642335
  1. 11
      cboard.c
  2. 3
      cboard.h
  3. 8
      tui_main.c

11
cboard.c

@ -19,9 +19,10 @@ Cboard_error cboard_copy(Glyph const* gbuffer, Usz field_height,
return status ? Cboard_error_process_exit_error : Cboard_error_none; return status ? Cboard_error_process_exit_error : Cboard_error_none;
} }
Cboard_error cboard_paste(Glyph* gbuffer, Usz height, Usz width, Usz y, Usz x) { Cboard_error cboard_paste(Glyph* gbuffer, Usz height, Usz width, Usz y, Usz x,
Usz* out_h, Usz* out_w) {
FILE* fp = popen("xclip -o -selection clipboard 2>/dev/null", "r"); FILE* fp = popen("xclip -o -selection clipboard 2>/dev/null", "r");
Usz start_x = x; Usz start_y = y, start_x = x, max_y = y, max_x = x;
if (!fp) if (!fp)
return Cboard_error_popen_failed; return Cboard_error_popen_failed;
char inbuff[512]; char inbuff[512];
@ -37,6 +38,10 @@ Cboard_error cboard_paste(Glyph* gbuffer, Usz height, Usz width, Usz y, Usz x) {
if (c != ' ' && y < height && x < width) { if (c != ' ' && y < height && x < width) {
Glyph g = is_valid_glyph((Glyph)c) ? (Glyph)c : '.'; Glyph g = is_valid_glyph((Glyph)c) ? (Glyph)c : '.';
gbuffer_poke(gbuffer, height, width, y, x, g); gbuffer_poke(gbuffer, height, width, y, x, g);
if (x > max_x)
max_x = x;
if (y > max_y)
max_y = y;
} }
x++; x++;
} }
@ -44,5 +49,7 @@ Cboard_error cboard_paste(Glyph* gbuffer, Usz height, Usz width, Usz y, Usz x) {
break; break;
} }
int status = pclose(fp); int status = pclose(fp);
*out_h = max_y - start_y + 1;
*out_w = max_x - start_x + 1;
return status ? Cboard_error_process_exit_error : Cboard_error_none; return status ? Cboard_error_process_exit_error : Cboard_error_none;
} }

3
cboard.h

@ -12,4 +12,5 @@ Cboard_error cboard_copy(Glyph const* gbuffer, Usz field_height,
Usz field_width, Usz rect_y, Usz rect_x, Usz rect_h, Usz field_width, Usz rect_y, Usz rect_x, Usz rect_h,
Usz rect_w); Usz rect_w);
Cboard_error cboard_paste(Glyph* gbuffer, Usz height, Usz width, Usz y, Usz x); Cboard_error cboard_paste(Glyph* gbuffer, Usz height, Usz width, Usz y, Usz x,
Usz* out_h, Usz* out_w);

8
tui_main.c

@ -3001,10 +3001,11 @@ int main(int argc, char** argv) {
if (use_gui_cboard) { if (use_gui_cboard) {
undo_history_push(&ged_state.undo_hist, &ged_state.field, undo_history_push(&ged_state.undo_hist, &ged_state.field,
ged_state.tick_num); ged_state.tick_num);
Usz pasted_h, pasted_w;
Cboard_error cberr = Cboard_error cberr =
cboard_paste(ged_state.field.buffer, ged_state.field.height, cboard_paste(ged_state.field.buffer, ged_state.field.height,
ged_state.field.width, ged_state.ged_cursor.y, ged_state.field.width, ged_state.ged_cursor.y,
ged_state.ged_cursor.x); ged_state.ged_cursor.x, &pasted_h, &pasted_w);
if (cberr) { if (cberr) {
undo_history_pop(&ged_state.undo_hist, &ged_state.field, undo_history_pop(&ged_state.undo_hist, &ged_state.field,
&ged_state.tick_num); &ged_state.tick_num);
@ -3018,6 +3019,11 @@ int main(int argc, char** argv) {
} }
use_gui_cboard = false; use_gui_cboard = false;
ged_input_cmd(&ged_state, Ged_input_cmd_paste); ged_input_cmd(&ged_state, Ged_input_cmd_paste);
} else {
if (pasted_h > 0 && pasted_w > 0) {
ged_state.ged_cursor.h = pasted_h;
ged_state.ged_cursor.w = pasted_w;
}
} }
ged_state.needs_remarking = true; ged_state.needs_remarking = true;
ged_state.is_draw_dirty = true; ged_state.is_draw_dirty = true;

Loading…
Cancel
Save