Adding fixime, newterm and opencopied patches
This commit is contained in:
parent
35e6403c69
commit
7615c2f0aa
15 changed files with 233 additions and 10 deletions
49
patch/fixime.c
Normal file
49
patch/fixime.c
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
void
|
||||
ximopen(Display *dpy)
|
||||
{
|
||||
XIMCallback destroy = { .client_data = NULL, .callback = ximdestroy };
|
||||
|
||||
if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
|
||||
XSetLocaleModifiers("@im=local");
|
||||
if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
|
||||
XSetLocaleModifiers("@im=");
|
||||
if ((xw.xim = XOpenIM(xw.dpy,
|
||||
NULL, NULL, NULL)) == NULL) {
|
||||
die("XOpenIM failed. Could not open input"
|
||||
" device.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (XSetIMValues(xw.xim, XNDestroyCallback, &destroy, NULL) != NULL)
|
||||
die("XSetIMValues failed. Could not set input method value.\n");
|
||||
xw.xic = XCreateIC(xw.xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
|
||||
XNClientWindow, xw.win, XNFocusWindow, xw.win, NULL);
|
||||
if (xw.xic == NULL)
|
||||
die("XCreateIC failed. Could not obtain input method.\n");
|
||||
}
|
||||
|
||||
void
|
||||
ximinstantiate(Display *dpy, XPointer client, XPointer call)
|
||||
{
|
||||
ximopen(dpy);
|
||||
XUnregisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
|
||||
ximinstantiate, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
ximdestroy(XIM xim, XPointer client, XPointer call)
|
||||
{
|
||||
xw.xim = NULL;
|
||||
XRegisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
|
||||
ximinstantiate, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
xximspot(int x, int y)
|
||||
{
|
||||
XPoint spot = { borderpx + x * win.cw, borderpx + (y + 1) * win.ch };
|
||||
XVaNestedList attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL);
|
||||
|
||||
XSetICValues(xw.xic, XNPreeditAttributes, attr, NULL);
|
||||
XFree(attr);
|
||||
}
|
||||
4
patch/fixime.h
Normal file
4
patch/fixime.h
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
static void ximopen(Display *);
|
||||
static void ximinstantiate(Display *, XPointer, XPointer);
|
||||
static void ximdestroy(XIM, XPointer, XPointer);
|
||||
void xximspot(int, int);
|
||||
20
patch/newterm.c
Normal file
20
patch/newterm.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
void
|
||||
newterm(const Arg* a)
|
||||
{
|
||||
int res;
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
die("fork failed: %s\n", strerror(errno));
|
||||
break;
|
||||
case 0:
|
||||
res = chdir(getcwd_by_pid(pid));
|
||||
execlp("st", "./st", NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static char *getcwd_by_pid(pid_t pid) {
|
||||
char buf[32];
|
||||
snprintf(buf, sizeof buf, "/proc/%d/cwd", pid);
|
||||
return realpath(buf, NULL);
|
||||
}
|
||||
2
patch/newterm.h
Normal file
2
patch/newterm.h
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
void newterm(const Arg *);
|
||||
static char *getcwd_by_pid(pid_t pid);
|
||||
19
patch/opencopied.c
Normal file
19
patch/opencopied.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
void
|
||||
opencopied(const Arg *arg)
|
||||
{
|
||||
int res;
|
||||
size_t const max_cmd = 2048;
|
||||
char * const clip = xsel.clipboard;
|
||||
if (!clip) {
|
||||
fprintf(stderr, "Warning: nothing copied to clipboard\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* account for space/quote (3) and \0 (1) and & (1) */
|
||||
/* e.g.: xdg-open "https://st.suckless.org"& */
|
||||
size_t const cmd_size = max_cmd + strlen(clip) + 5;
|
||||
char cmd[cmd_size];
|
||||
|
||||
snprintf(cmd, cmd_size, "%s \"%s\"&", (char *)arg->v, clip);
|
||||
res = system(cmd);
|
||||
}
|
||||
1
patch/opencopied.h
Normal file
1
patch/opencopied.h
Normal file
|
|
@ -0,0 +1 @@
|
|||
void opencopied(const Arg *);
|
||||
|
|
@ -2,4 +2,8 @@
|
|||
|
||||
#if COPYURL_PATCH || COPYURL_HIGHLIGHT_SELECTED_URLS_PATCH
|
||||
#include "copyurl.c"
|
||||
#endif
|
||||
|
||||
#if NEWTERM_PATCH
|
||||
#include "newterm.c"
|
||||
#endif
|
||||
|
|
@ -2,4 +2,12 @@
|
|||
|
||||
#if COPYURL_PATCH || COPYURL_HIGHLIGHT_SELECTED_URLS_PATCH
|
||||
#include "copyurl.h"
|
||||
#endif
|
||||
|
||||
#if FIXIME_PATCH
|
||||
void xximspot(int, int);
|
||||
#endif
|
||||
|
||||
#if NEWTERM_PATCH
|
||||
#include "newterm.h"
|
||||
#endif
|
||||
9
patch/x_include.c
Normal file
9
patch/x_include.c
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/* Patches */
|
||||
|
||||
#if OPENCOPIED_PATCH
|
||||
#include "opencopied.c"
|
||||
#endif
|
||||
|
||||
#if FIXIME_PATCH
|
||||
#include "fixime.c"
|
||||
#endif
|
||||
9
patch/x_include.h
Normal file
9
patch/x_include.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/* Patches */
|
||||
|
||||
#if OPENCOPIED_PATCH
|
||||
#include "opencopied.h"
|
||||
#endif
|
||||
|
||||
#if FIXIME_PATCH
|
||||
#include "fixime.h"
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue