Skip to content

Commit

Permalink
Use new glfwSetSelectionString() API to set X11 primary selection
Browse files Browse the repository at this point in the history
This was implemented as a modification to thirdparty/glfw. It avoids the
need to spawn an external program xsel.

Patch against GLFW:

  knielsen/glfw@3a6608e
  • Loading branch information
knielsen committed Aug 2, 2017
1 parent e90301a commit 1df5667
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions platform/gl/gl-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,6 @@ static void pop_future(void)
push_history();
}

#ifndef _WIN32
/*
Set the X11 primary selection (as opposed to clipboard selection).
The GLFW library does not seem to support the primary selection (issue
Expand All @@ -449,6 +448,10 @@ static void pop_future(void)
*/
static void do_set_primary_selection(const char *data)
{
#ifdef GLFW_MUPDF_FIXES
glfwSetSelectionString(window, data);
#else
#ifndef _WIN32
int pipefd[2];
int err;
pid_t pid;
Expand Down Expand Up @@ -515,8 +518,9 @@ static void do_set_primary_selection(const char *data)
fz_warn(ctx, "Cannot set primary selection: running xsel failed.");
break;
}
}
#endif
#endif
}

static void do_copy_region(fz_rect *screen_sel, int xofs, int yofs)
{
Expand Down Expand Up @@ -545,9 +549,9 @@ static void do_copy_region(fz_rect *screen_sel, int xofs, int yofs)
buf = fz_new_buffer_from_page(ctx, which_page, &page_sel, 1, NULL);
#else
buf = fz_new_buffer_from_page(ctx, which_page, &page_sel, 0, NULL);
do_set_primary_selection(fz_string_from_buffer(ctx, buf));
#endif
glfwSetClipboardString(window, fz_string_from_buffer(ctx, buf));
do_set_primary_selection(fz_string_from_buffer(ctx, buf));
fz_drop_buffer(ctx, buf);
}

Expand Down Expand Up @@ -1106,9 +1110,7 @@ static void do_char_selection(int x0, int y0, int x1, int y1)
{
const char *text = fz_string_from_buffer(ctx, selection_buf);
glfwSetClipboardString(window, text);
#ifndef _WIN32
do_set_primary_selection(text);
#endif
fz_drop_buffer(ctx, selection_buf);
selection_buf = NULL;
}
Expand Down

0 comments on commit 1df5667

Please sign in to comment.