summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-08-02 14:59:15 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-08-02 14:59:15 +0300
commit037ff0807f92ebc650c02846ac2bc6ce3cdecdf4 (patch)
treeae1a5b323136b043e59aa8298fdfe68c2ef1638d
parenteb2a59e2506ba77799d381420aba2ddedaaaa9b8 (diff)
Added --tab-url option to print active tab's URL
IssueID #319
-rw-r--r--res/arg-help.txt1
-rw-r--r--src/app.c10
-rw-r--r--src/ipc.c2
3 files changed, 13 insertions, 0 deletions
diff --git a/res/arg-help.txt b/res/arg-help.txt
index e87881d3..9f6548f2 100644
--- a/res/arg-help.txt
+++ b/res/arg-help.txt
@@ -21,3 +21,4 @@ Options that control a running instance of Lagrange:
21 running, nothing is printed. 21 running, nothing is printed.
22 --new-tab [URL] Open a new tab. If the URL is omitted, the user's 22 --new-tab [URL] Open a new tab. If the URL is omitted, the user's
23 homepage is opened. 23 homepage is opened.
24 --tab-url Print the URL of the active tab.
diff --git a/src/app.c b/src/app.c
index abfd584a..8318eee4 100644
--- a/src/app.c
+++ b/src/app.c
@@ -581,6 +581,9 @@ static void communicateWithRunningInstance_App_(iApp *d, iProcessId instance,
581 else if (equal_CommandLineConstIterator(&i, "close-tab")) { 581 else if (equal_CommandLineConstIterator(&i, "close-tab")) {
582 appendCStr_String(cmds, "tabs.close\n"); 582 appendCStr_String(cmds, "tabs.close\n");
583 } 583 }
584 else if (equal_CommandLineConstIterator(&i, "tab-url")) {
585 appendFormat_String(cmds, "ipc.active.url pid:%d\n", pid);
586 }
584 else if (equal_CommandLineConstIterator(&i, listTabUrls_CommandLineOption)) { 587 else if (equal_CommandLineConstIterator(&i, listTabUrls_CommandLineOption)) {
585 appendFormat_String(cmds, "ipc.list.urls pid:%d\n", pid); 588 appendFormat_String(cmds, "ipc.list.urls pid:%d\n", pid);
586 } 589 }
@@ -658,6 +661,7 @@ static void init_App_(iApp *d, int argc, char **argv) {
658 defineValues_CommandLine(&d->args, listTabUrls_CommandLineOption, 0); 661 defineValues_CommandLine(&d->args, listTabUrls_CommandLineOption, 0);
659 defineValues_CommandLine(&d->args, openUrlOrSearch_CommandLineOption, 1); 662 defineValues_CommandLine(&d->args, openUrlOrSearch_CommandLineOption, 1);
660 defineValuesN_CommandLine(&d->args, "new-tab", 0, 1); 663 defineValuesN_CommandLine(&d->args, "new-tab", 0, 1);
664 defineValues_CommandLine(&d->args, "tab-url", 0);
661 defineValues_CommandLine(&d->args, "sw", 0); 665 defineValues_CommandLine(&d->args, "sw", 0);
662 defineValues_CommandLine(&d->args, "version;V", 0); 666 defineValues_CommandLine(&d->args, "version;V", 0);
663 } 667 }
@@ -2772,6 +2776,12 @@ iBool handleCommand_App(const char *cmd) {
2772 } 2776 }
2773 return iTrue; 2777 return iTrue;
2774 } 2778 }
2779 else if (equal_Command(cmd, "ipc.active.url")) {
2780 write_Ipc(argLabel_Command(cmd, "pid"),
2781 collectNewFormat_String("%s\n", cstr_String(url_DocumentWidget(document_App()))),
2782 response_IpcWrite);
2783 return iTrue;
2784 }
2775 else if (equal_Command(cmd, "ipc.signal")) { 2785 else if (equal_Command(cmd, "ipc.signal")) {
2776 if (argLabel_Command(cmd, "raise")) { 2786 if (argLabel_Command(cmd, "raise")) {
2777 if (d->window && d->window->win) { 2787 if (d->window && d->window->win) {
diff --git a/src/ipc.c b/src/ipc.c
index ce98b6cf..e4c95c50 100644
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -172,6 +172,7 @@ static void handleSignal_IpcResponse_(int sig) {
172} 172}
173 173
174iBool write_Ipc(iProcessId pid, const iString *input, enum iIpcWrite type) { 174iBool write_Ipc(iProcessId pid, const iString *input, enum iIpcWrite type) {
175 if (!pid) return iFalse;
175 iBool ok = iFalse; 176 iBool ok = iFalse;
176 iFile *f = newCStr_File(inputFilePath_(&ipc_, pid)); 177 iFile *f = newCStr_File(inputFilePath_(&ipc_, pid));
177 if (open_File(f, text_FileMode | append_FileMode)) { 178 if (open_File(f, text_FileMode | append_FileMode)) {
@@ -281,6 +282,7 @@ void listen_Ipc(void) {
281} 282}
282 283
283iBool write_Ipc(iProcessId pid, const iString *input, enum iIpcWrite type) { 284iBool write_Ipc(iProcessId pid, const iString *input, enum iIpcWrite type) {
285 if (!pid) return iFalse;
284 iUnused(type); 286 iUnused(type);
285 HANDLE slot = CreateFile(slotName_(pid), 287 HANDLE slot = CreateFile(slotName_(pid),
286 GENERIC_WRITE, 288 GENERIC_WRITE,