summaryrefslogtreecommitdiff
path: root/src/history.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-06-14 15:36:48 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-06-14 15:36:48 +0300
commitfe238b29132b43f07aa88cf6bb60bec1ff0d3f8d (patch)
tree34d08228270960a73f5586ae907a12d7adb7b393 /src/history.c
parent203426a88b2d94ed56f7d3f8f8eb18a7457cab11 (diff)
Swiping and sidebar; various tweaks
When a page is opened from the sidebar, swiping back will now reopen the sidebar. Another swipe will dismiss the sidebar and navigate back as usual. Attempted to cache theme colors in GmDocument, but there were issues with theme changes.
Diffstat (limited to 'src/history.c')
-rw-r--r--src/history.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/history.c b/src/history.c
index d23fb290..c592838e 100644
--- a/src/history.c
+++ b/src/history.c
@@ -37,6 +37,7 @@ void init_RecentUrl(iRecentUrl *d) {
37 d->normScrollY = 0; 37 d->normScrollY = 0;
38 d->cachedResponse = NULL; 38 d->cachedResponse = NULL;
39 d->cachedDoc = NULL; 39 d->cachedDoc = NULL;
40 d->flags.openedFromSidebar = iFalse;
40} 41}
41 42
42void deinit_RecentUrl(iRecentUrl *d) { 43void deinit_RecentUrl(iRecentUrl *d) {
@@ -53,6 +54,7 @@ iRecentUrl *copy_RecentUrl(const iRecentUrl *d) {
53 copy->normScrollY = d->normScrollY; 54 copy->normScrollY = d->normScrollY;
54 copy->cachedResponse = d->cachedResponse ? copy_GmResponse(d->cachedResponse) : NULL; 55 copy->cachedResponse = d->cachedResponse ? copy_GmResponse(d->cachedResponse) : NULL;
55 copy->cachedDoc = ref_Object(d->cachedDoc); 56 copy->cachedDoc = ref_Object(d->cachedDoc);
57 copy->flags = d->flags;
56 return copy; 58 return copy;
57} 59}
58 60
@@ -171,6 +173,7 @@ void serialize_History(const iHistory *d, iStream *outs) {
171 const iRecentUrl *item = i.value; 173 const iRecentUrl *item = i.value;
172 serialize_String(&item->url, outs); 174 serialize_String(&item->url, outs);
173 write32_Stream(outs, item->normScrollY * 1.0e6f); 175 write32_Stream(outs, item->normScrollY * 1.0e6f);
176 writeU16_Stream(outs, item->flags.openedFromSidebar ? iBit(1) : 0);
174 if (item->cachedResponse) { 177 if (item->cachedResponse) {
175 write8_Stream(outs, 1); 178 write8_Stream(outs, 1);
176 serialize_GmResponse(item->cachedResponse, outs); 179 serialize_GmResponse(item->cachedResponse, outs);
@@ -192,6 +195,12 @@ void deserialize_History(iHistory *d, iStream *ins) {
192 init_RecentUrl(&item); 195 init_RecentUrl(&item);
193 deserialize_String(&item.url, ins); 196 deserialize_String(&item.url, ins);
194 item.normScrollY = (float) read32_Stream(ins) / 1.0e6f; 197 item.normScrollY = (float) read32_Stream(ins) / 1.0e6f;
198 if (version_Stream(ins) >= addedRecentUrlFlags_FileVersion) {
199 uint16_t flags = readU16_Stream(ins);
200 if (flags & iBit(1)) {
201 item.flags.openedFromSidebar = iTrue;
202 }
203 }
195 if (read8_Stream(ins)) { 204 if (read8_Stream(ins)) {
196 item.cachedResponse = new_GmResponse(); 205 item.cachedResponse = new_GmResponse();
197 deserialize_GmResponse(item.cachedResponse, ins); 206 deserialize_GmResponse(item.cachedResponse, ins);
@@ -378,12 +387,15 @@ void setCachedResponse_History(iHistory *d, const iGmResponse *response) {
378 unlock_Mutex(d->mtx); 387 unlock_Mutex(d->mtx);
379} 388}
380 389
381void setCachedDocument_History(iHistory *d, iGmDocument *doc) { 390void setCachedDocument_History(iHistory *d, iGmDocument *doc, iBool openedFromSidebar) {
382 lock_Mutex(d->mtx); 391 lock_Mutex(d->mtx);
383 iRecentUrl *item = mostRecentUrl_History(d); 392 iRecentUrl *item = mostRecentUrl_History(d);
384 if (item && item->cachedDoc != doc) { 393 if (item) {
385 iRelease(item->cachedDoc); 394 item->flags.openedFromSidebar = openedFromSidebar;
386 item->cachedDoc = ref_Object(doc); 395 if (item->cachedDoc != doc) {
396 iRelease(item->cachedDoc);
397 item->cachedDoc = ref_Object(doc);
398 }
387 } 399 }
388 unlock_Mutex(d->mtx); 400 unlock_Mutex(d->mtx);
389} 401}
@@ -487,6 +499,17 @@ size_t pruneLeastImportantMemory_History(iHistory *d) {
487 return delta; 499 return delta;
488} 500}
489 501
502void invalidateTheme_History(iHistory *d) {
503 lock_Mutex(d->mtx);
504 iForEach(Array, i, &d->recent) {
505 iRecentUrl *r = i.value;
506 if (r->cachedDoc) {
507 invalidatePalette_GmDocument(r->cachedDoc);
508 }
509 }
510 unlock_Mutex(d->mtx);
511}
512
490const iStringArray *searchContents_History(const iHistory *d, const iRegExp *pattern) { 513const iStringArray *searchContents_History(const iHistory *d, const iRegExp *pattern) {
491 iStringArray *urls = iClob(new_StringArray()); 514 iStringArray *urls = iClob(new_StringArray());
492 lock_Mutex(d->mtx); 515 lock_Mutex(d->mtx);