-
-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Display disconnected icon before closing #6662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+436
−87
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8a4955e
Rename icon.png to scrcpy.png
rom1v c994f9d
Extract function to build file paths
rom1v d659073
Replace SCRCPY_ICON_PATH with SCRCPY_ICON_DIR
rom1v 6ca1b79
Add filename parameter to icon loading
rom1v a2055c0
Add function to delete current texture
rom1v fe1fd55
Add utility to push an SDL event with data
rom1v 6bf8b8d
Only reject RUN_ON_MAIN_THREAD events on quit
rom1v a4000a1
Display disconnected icon before closing
rom1v File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| #include "disconnect.h" | ||
|
|
||
| #include <assert.h> | ||
|
|
||
| #include "icon.h" | ||
| #include "util/log.h" | ||
|
|
||
| static int | ||
| run(void *userdata) { | ||
| struct sc_disconnect *d = userdata; | ||
|
|
||
| SDL_Surface *icon = sc_icon_load(SC_ICON_FILENAME_DISCONNECTED); | ||
| if (icon) { | ||
| d->cbs->on_icon_loaded(d, icon, d->cbs_userdata); | ||
| } else { | ||
| LOGE("Could not load disconnected icon"); | ||
| } | ||
|
|
||
| sc_mutex_lock(&d->mutex); | ||
| bool timed_out = false; | ||
| while (!d->interrupted && !timed_out) { | ||
| timed_out = !sc_cond_timedwait(&d->cond, &d->mutex, d->deadline); | ||
| } | ||
| bool interrupted = d->interrupted; | ||
| sc_mutex_unlock(&d->mutex); | ||
|
|
||
| if (!interrupted) { | ||
| d->cbs->on_timeout(d, d->cbs_userdata); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| bool | ||
| sc_disconnect_start(struct sc_disconnect *d, sc_tick deadline, | ||
| const struct sc_disconnect_callbacks *cbs, | ||
| void *cbs_userdata) { | ||
| bool ok = sc_mutex_init(&d->mutex); | ||
| if (!ok) { | ||
| return false; | ||
| } | ||
|
|
||
| ok = sc_cond_init(&d->cond); | ||
| if (!ok) { | ||
| goto error_destroy_mutex; | ||
| } | ||
|
|
||
| d->deadline = deadline; | ||
| d->interrupted = false; | ||
|
|
||
| assert(cbs && cbs->on_icon_loaded && cbs->on_timeout); | ||
| d->cbs = cbs; | ||
| d->cbs_userdata = cbs_userdata; | ||
|
|
||
| ok = sc_thread_create(&d->thread, run, "scrcpy-dis", d); | ||
| if (!ok) { | ||
| goto error_destroy_cond; | ||
| } | ||
|
|
||
| return true; | ||
|
|
||
| error_destroy_cond: | ||
| sc_cond_destroy(&d->cond); | ||
| error_destroy_mutex: | ||
| sc_mutex_destroy(&d->mutex); | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| void | ||
| sc_disconnect_interrupt(struct sc_disconnect *d) { | ||
| sc_mutex_lock(&d->mutex); | ||
| d->interrupted = true; | ||
| sc_mutex_unlock(&d->mutex); | ||
| // wake up blocking wait | ||
| sc_cond_signal(&d->cond); | ||
| } | ||
|
|
||
| void | ||
| sc_disconnect_join(struct sc_disconnect *d) { | ||
| sc_thread_join(&d->thread, NULL); | ||
| } | ||
|
|
||
| void | ||
| sc_disconnect_destroy(struct sc_disconnect *d) { | ||
| sc_cond_destroy(&d->cond); | ||
| sc_mutex_destroy(&d->mutex); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #ifndef SC_DISCONNECT | ||
| #define SC_DISCONNECT | ||
|
|
||
| #include "common.h" | ||
|
|
||
| #include "SDL3/SDL_surface.h" | ||
| #include "util/tick.h" | ||
| #include "util/thread.h" | ||
|
|
||
| // Tool to handle loading the icon and signal timeout when the device is | ||
| // unexpectedly disconnected | ||
| struct sc_disconnect { | ||
| sc_tick deadline; | ||
|
|
||
| struct sc_thread thread; | ||
| struct sc_mutex mutex; | ||
| struct sc_cond cond; | ||
| bool interrupted; | ||
|
|
||
| const struct sc_disconnect_callbacks *cbs; | ||
| void *cbs_userdata; | ||
| }; | ||
|
|
||
| struct sc_disconnect_callbacks { | ||
| // Called when the disconnected icon is loaded | ||
| void (*on_icon_loaded)(struct sc_disconnect *d, SDL_Surface *icon, | ||
| void *userdata); | ||
|
|
||
| // Called when the timeout expired (the scrcpy window must be closed) | ||
| void (*on_timeout)(struct sc_disconnect *d, void *userdata); | ||
| }; | ||
|
|
||
| bool | ||
| sc_disconnect_start(struct sc_disconnect *d, sc_tick deadline, | ||
| const struct sc_disconnect_callbacks *cbs, | ||
| void *cbs_userdata); | ||
|
|
||
| void | ||
| sc_disconnect_interrupt(struct sc_disconnect *d); | ||
|
|
||
| void | ||
| sc_disconnect_join(struct sc_disconnect *d); | ||
|
|
||
| void | ||
| sc_disconnect_destroy(struct sc_disconnect *d); | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.