diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-05-21 11:38:15 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-05-21 11:38:15 +0300 |
commit | f033188b8103135b4e4ce1746bfc26a527323ba8 (patch) | |
tree | b8d385d765836fa38a7b318d4fa870eb70fadeb7 /src | |
parent | aa3690044d7096c20a6608a5c7fb0546d407da5a (diff) |
IPC: Request window raise when opening new tabs, navigating
IssueID #234
Diffstat (limited to 'src')
-rw-r--r-- | src/app.c | 11 | ||||
-rw-r--r-- | src/ipc.c | 13 | ||||
-rw-r--r-- | src/ipc.h | 3 |
3 files changed, 19 insertions, 8 deletions
@@ -545,6 +545,7 @@ static void terminate_App_(int rc) { | |||
545 | static void communicateWithRunningInstance_App_(iApp *d, iProcessId instance, | 545 | static void communicateWithRunningInstance_App_(iApp *d, iProcessId instance, |
546 | const iStringList *openCmds) { | 546 | const iStringList *openCmds) { |
547 | iString *cmds = new_String(); | 547 | iString *cmds = new_String(); |
548 | iBool requestRaise = iFalse; | ||
548 | const iProcessId pid = currentId_Process(); | 549 | const iProcessId pid = currentId_Process(); |
549 | iConstForEach(CommandLine, i, &d->args) { | 550 | iConstForEach(CommandLine, i, &d->args) { |
550 | if (i.argType == value_CommandLineArgType) { | 551 | if (i.argType == value_CommandLineArgType) { |
@@ -552,6 +553,7 @@ static void communicateWithRunningInstance_App_(iApp *d, iProcessId instance, | |||
552 | } | 553 | } |
553 | if (equal_CommandLineConstIterator(&i, "go-home")) { | 554 | if (equal_CommandLineConstIterator(&i, "go-home")) { |
554 | appendCStr_String(cmds, "navigate.home\n"); | 555 | appendCStr_String(cmds, "navigate.home\n"); |
556 | requestRaise = iTrue; | ||
555 | } | 557 | } |
556 | else if (equal_CommandLineConstIterator(&i, "new-tab")) { | 558 | else if (equal_CommandLineConstIterator(&i, "new-tab")) { |
557 | iCommandLineArg *arg = argument_CommandLineConstIterator(&i); | 559 | iCommandLineArg *arg = argument_CommandLineConstIterator(&i); |
@@ -563,6 +565,7 @@ static void communicateWithRunningInstance_App_(iApp *d, iProcessId instance, | |||
563 | appendCStr_String(cmds, "tabs.new\n"); | 565 | appendCStr_String(cmds, "tabs.new\n"); |
564 | } | 566 | } |
565 | iRelease(arg); | 567 | iRelease(arg); |
568 | requestRaise = iTrue; | ||
566 | } | 569 | } |
567 | else if (equal_CommandLineConstIterator(&i, "close-tab")) { | 570 | else if (equal_CommandLineConstIterator(&i, "close-tab")) { |
568 | appendCStr_String(cmds, "tabs.close\n"); | 571 | appendCStr_String(cmds, "tabs.close\n"); |
@@ -577,9 +580,10 @@ static void communicateWithRunningInstance_App_(iApp *d, iProcessId instance, | |||
577 | if (isEmpty_String(cmds)) { | 580 | if (isEmpty_String(cmds)) { |
578 | /* By default open a new tab. */ | 581 | /* By default open a new tab. */ |
579 | appendCStr_String(cmds, "tabs.new\n"); | 582 | appendCStr_String(cmds, "tabs.new\n"); |
583 | requestRaise = iTrue; | ||
580 | } | 584 | } |
581 | if (!isEmpty_String(cmds)) { | 585 | if (!isEmpty_String(cmds)) { |
582 | iString *result = communicate_Ipc(cmds); | 586 | iString *result = communicate_Ipc(cmds, requestRaise); |
583 | if (result) { | 587 | if (result) { |
584 | fwrite(cstr_String(result), 1, size_String(result), stdout); | 588 | fwrite(cstr_String(result), 1, size_String(result), stdout); |
585 | fflush(stdout); | 589 | fflush(stdout); |
@@ -2507,6 +2511,11 @@ iBool handleCommand_App(const char *cmd) { | |||
2507 | return iTrue; | 2511 | return iTrue; |
2508 | } | 2512 | } |
2509 | else if (equal_Command(cmd, "ipc.signal")) { | 2513 | else if (equal_Command(cmd, "ipc.signal")) { |
2514 | if (argLabel_Command(cmd, "raise")) { | ||
2515 | if (d->window && d->window->win) { | ||
2516 | SDL_RaiseWindow(d->window->win); | ||
2517 | } | ||
2518 | } | ||
2510 | signal_Ipc(arg_Command(cmd)); | 2519 | signal_Ipc(arg_Command(cmd)); |
2511 | return iTrue; | 2520 | return iTrue; |
2512 | } | 2521 | } |
@@ -176,8 +176,9 @@ iBool write_Ipc(iProcessId pid, const iString *input, enum iIpcWrite type) { | |||
176 | iFile *f = newCStr_File(inputFilePath_(&ipc_, pid)); | 176 | iFile *f = newCStr_File(inputFilePath_(&ipc_, pid)); |
177 | if (open_File(f, text_FileMode | append_FileMode)) { | 177 | if (open_File(f, text_FileMode | append_FileMode)) { |
178 | write_File(f, utf8_String(input)); | 178 | write_File(f, utf8_String(input)); |
179 | if (type == command_IpcWrite) { | 179 | if (type != response_IpcWrite) { |
180 | printf_Stream(stream_File(f), "\nipc.signal arg:%d\n", currentId_Process()); | 180 | printf_Stream(stream_File(f), "\nipc.signal arg:%d%s\n", currentId_Process(), |
181 | type == commandAndRaise_IpcWrite ? " raise:1" : ""); | ||
181 | } | 182 | } |
182 | close_File(f); | 183 | close_File(f); |
183 | ok = iTrue; | 184 | ok = iTrue; |
@@ -186,10 +187,10 @@ iBool write_Ipc(iProcessId pid, const iString *input, enum iIpcWrite type) { | |||
186 | return ok; | 187 | return ok; |
187 | } | 188 | } |
188 | 189 | ||
189 | iString *communicate_Ipc(const iString *command) { | 190 | iString *communicate_Ipc(const iString *command, iBool requestRaise) { |
190 | const iProcessId dst = check_Ipc(); | 191 | const iProcessId dst = check_Ipc(); |
191 | if (dst) { | 192 | if (dst) { |
192 | if (write_Ipc(dst, command, command_IpcWrite)) { | 193 | if (write_Ipc(dst, command, requestRaise ? commandAndRaise_IpcWrite : command_IpcWrite)) { |
193 | response_ = new_IpcResponse(); | 194 | response_ = new_IpcResponse(); |
194 | signal(SIGUSR1, handleSignal_IpcResponse_); | 195 | signal(SIGUSR1, handleSignal_IpcResponse_); |
195 | lock_Mutex(&response_->mtx); | 196 | lock_Mutex(&response_->mtx); |
@@ -300,7 +301,7 @@ iBool write_Ipc(iProcessId pid, const iString *input, enum iIpcWrite type) { | |||
300 | return ok; | 301 | return ok; |
301 | } | 302 | } |
302 | 303 | ||
303 | iString *communicate_Ipc(const iString *command) { | 304 | iString *communicate_Ipc(const iString *command, iBool requestRaise) { |
304 | iProcessId pid = check_Ipc(); | 305 | iProcessId pid = check_Ipc(); |
305 | if (!pid) { | 306 | if (!pid) { |
306 | return NULL; | 307 | return NULL; |
@@ -308,7 +309,7 @@ iString *communicate_Ipc(const iString *command) { | |||
308 | /* Open a mailslot for the response. */ | 309 | /* Open a mailslot for the response. */ |
309 | HANDLE responseSlot = CreateMailslotA(slotName_(currentId_Process()), 0, 1000, NULL); | 310 | HANDLE responseSlot = CreateMailslotA(slotName_(currentId_Process()), 0, 1000, NULL); |
310 | /* Write the commands. */ | 311 | /* Write the commands. */ |
311 | if (!write_Ipc(pid, command, command_IpcWrite)) { | 312 | if (!write_Ipc(pid, command, requestRaise ? commandAndRaise_IpcWrite : command_IpcWrite)) { |
312 | CloseHandle(responseSlot); | 313 | CloseHandle(responseSlot); |
313 | return NULL; | 314 | return NULL; |
314 | } | 315 | } |
@@ -31,11 +31,12 @@ void deinit_Ipc (void); | |||
31 | 31 | ||
32 | iProcessId check_Ipc (void); | 32 | iProcessId check_Ipc (void); |
33 | void listen_Ipc (void); | 33 | void listen_Ipc (void); |
34 | iString * communicate_Ipc (const iString *command); | 34 | iString * communicate_Ipc (const iString *command, iBool requestRaise); |
35 | void signal_Ipc (iProcessId pid); | 35 | void signal_Ipc (iProcessId pid); |
36 | 36 | ||
37 | enum iIpcWrite { | 37 | enum iIpcWrite { |
38 | command_IpcWrite, | 38 | command_IpcWrite, |
39 | commandAndRaise_IpcWrite, | ||
39 | response_IpcWrite, | 40 | response_IpcWrite, |
40 | }; | 41 | }; |
41 | 42 | ||