Difference between revisions of "Patch Launcher Reset Scroll on Page Change"

From WebOS Internals
Jump to: navigation, search
m (Introduction)
(A new version of the patch that is compatible with the Wrap Pages patch - it modifies different parts of the file now.)
Line 3: Line 3:
  
 
If you have many apps on a page, you may have to scroll to see some of those. The launcher maintains the scroll state (the amount you have scrolled) on each page, which means when you return to a page, you are still at the location that you last scrolled to. This can be annoying. For example, it can make it difficult to train your muscle memory because, when repeating the same steps, the app you want is not always at the same location on the screen. This patch resets the scroll of each page back to the top when it goes out of view.
 
If you have many apps on a page, you may have to scroll to see some of those. The launcher maintains the scroll state (the amount you have scrolled) on each page, which means when you return to a page, you are still at the location that you last scrolled to. This can be annoying. For example, it can make it difficult to train your muscle memory because, when repeating the same steps, the app you want is not always at the same location on the screen. This patch resets the scroll of each page back to the top when it goes out of view.
 +
 +
Update Dec '09: I've changed the way the patch is implemented, this new version is now compatible with the Wrap Pages patch.
  
 
==Editing Process==
 
==Editing Process==
Line 15: Line 17:
 
sudo vi /usr/lib/luna/system/luna-applauncher/app/controllers/launcher-assistant.js
 
sudo vi /usr/lib/luna/system/luna-applauncher/app/controllers/launcher-assistant.js
 
</source></blockquote>
 
</source></blockquote>
* Locate the onPageChange method around line 157 (line 158 in webOS 1.2):
+
* Locate the end of the setup method, around line 98:
 +
<blockquote><source lang="javascript">
 +
// setup the initial dimensions for launcher/global-search
 +
this.adjustLayout();
 +
},
 +
 +
ready: function() {
 +
this.globalSearchAssistant.ready();
 +
},
 +
</source></blockquote>
 +
* Add the lines below to the end of the setup method (that is, make sure they're inside the '},' before the ready method on line 102), so that it now looks like this:
 
<blockquote><source lang="javascript">
 
<blockquote><source lang="javascript">
onPageChange: function(event) {
+
// setup the initial dimensions for launcher/global-search
this.activePageIndex = event.value;
+
this.adjustLayout();
this.updatePageIndicators();
+
 
},
+
// add a separate listener for resetting the scroll position on page changes, and also on deactivate
 +
Mojo.listen($('launcher_root'), Mojo.Event.propertyChange, this.resetScrollPosition.bindAsEventListener(this));
 +
Mojo.listen(this.controller.document, Mojo.Event.deactivate, this.resetScrollPosition.bindAsEventListener(this));
 +
},
 +
 +
ready: function() {
 +
this.globalSearchAssistant.ready();
 +
},
 
</source></blockquote>
 
</source></blockquote>
* Add the four lines below so that onPageChange now looks like the following:
+
* Add the following method somewhere else in the file, I suggest just below the ready method and before the deleteAllPages method, around line 105 (don't forget the comma after the closing brace, unless you add it right at the end of the class, as the last method):
 
<blockquote><source lang="javascript">
 
<blockquote><source lang="javascript">
onPageChange: function(event) {
+
resetScrollPosition: function(event) {
var scroller = this.getPageScroller(this.activePageIndex);
+
var pageIndex = (event.type === 'mojo-event-deactivate') ? this.activePageIndex : event.value;
if (scroller && scroller.mojo) {
+
var scroller = this.getPageScroller(pageIndex);
scroller.mojo.revealTop(0);
+
if (scroller && scroller.mojo) { scroller.mojo.revealTop(); }
}
+
},
this.activePageIndex = event.value;
 
this.updatePageIndicators();
 
},
 
 
</source></blockquote>
 
</source></blockquote>
 
* Save the file and quit vi.
 
* Save the file and quit vi.
Line 42: Line 58:
 
==Patch Process==
 
==Patch Process==
  
The patch should soon be located in the webos-internals gitorious repository. Until then, you can copy and paste the source below. Visit [[Applying Patches]] for info on how to use it. To apply the patch, follow the instructions above, and after remounting the filesystem as read/write, do the following:
+
An older version of the patch is in the git/Preware repository, hopefully this version will be submitted soon. Until then, you can copy and paste the source below. Visit [[Applying Patches]] for info on how to use it. You can also apply it using webOS Quick Install. To apply the patch, follow the instructions above, and after remounting the filesystem as read/write, do the following:
  
 
* Apply the patch (In this example, I have the patch file located in my home directory under '''patches'''):
 
* Apply the patch (In this example, I have the patch file located in my home directory under '''patches'''):
Line 60: Line 76:
  
 
<source lang="diff">
 
<source lang="diff">
--- /usr/lib/luna/system/luna-applauncher/app/controllers/launcher-assistant.js.bak 2009-05-22 17:12:34.000000000 -0400
+
--- /usr/lib/luna/system/luna-applauncher/app/controllers/launcher-assistant.js.orig Sat Dec  5 11:48:12 2009
+++ /usr/lib/luna/system/luna-applauncher/app/controllers/launcher-assistant.js 2009-08-21 17:19:48.426297000 -0400
+
+++ /usr/lib/luna/system/luna-applauncher/app/controllers/launcher-assistant.js Thu Dec  3 19:42:03 2009
@@ -155,6 +155,10 @@
+
@@ -98,5 +98,9 @@
 +
// setup the initial dimensions for launcher/global-search
 +
this.adjustLayout();
 +
+
 +
+ // add a separate listener for resetting the scroll position on page changes, and also on deactivate
 +
+ Mojo.listen($('launcher_root'), Mojo.Event.propertyChange, this.resetScrollPosition.bindAsEventListener(this));
 +
+ Mojo.listen(this.controller.document, Mojo.Event.deactivate, this.resetScrollPosition.bindAsEventListener(this));
 +
},
 
 
 
 
  /* keep track of which page we are on */
+
  ready: function() {
onPageChange: function(event) {
+
@@ -188,6 +188,12 @@
+       var scroller = this.getPageScroller(this.activePageIndex);
+
onResize: function(event) {
+        if (scroller && scroller.mojo) {
+
  this.adjustLayout();
+            scroller.mojo.revealTop(0);
 
+        }
 
this.activePageIndex = event.value;
 
  this.updatePageIndicators();
 
 
  },
 
  },
 +
 +
+ resetScrollPosition: function(event) {
 +
+ var pageIndex = (event.type === 'mojo-event-deactivate') ? this.activePageIndex : event.value;
 +
+ var scroller = this.getPageScroller(pageIndex);
 +
+ if (scroller && scroller.mojo) { scroller.mojo.revealTop(); }
 +
+ },
 +
+
 +
/* remove page data and their corresponding HTML */
 +
deleteAllPages: function() {
 +
 +
 
</source>
 
</source>

Revision as of 06:55, 5 December 2009

<<- Return to webOS Patches


Introduction

If you have many apps on a page, you may have to scroll to see some of those. The launcher maintains the scroll state (the amount you have scrolled) on each page, which means when you return to a page, you are still at the location that you last scrolled to. This can be annoying. For example, it can make it difficult to train your muscle memory because, when repeating the same steps, the app you want is not always at the same location on the screen. This patch resets the scroll of each page back to the top when it goes out of view.

Update Dec '09: I've changed the way the patch is implemented, this new version is now compatible with the Wrap Pages patch.

Editing Process

  • SSH in.
  • Remount the filesystem as read/write:
<source lang="bash">

sudo rootfs_open -w

</source>
  • Load launcher-assistant.js in vi:
<source lang="bash">

sudo vi /usr/lib/luna/system/luna-applauncher/app/controllers/launcher-assistant.js

</source>
  • Locate the end of the setup method, around line 98:
<source lang="javascript">

// setup the initial dimensions for launcher/global-search this.adjustLayout(); },

ready: function() { this.globalSearchAssistant.ready(); },

</source>
  • Add the lines below to the end of the setup method (that is, make sure they're inside the '},' before the ready method on line 102), so that it now looks like this:
<source lang="javascript">

// setup the initial dimensions for launcher/global-search this.adjustLayout();

// add a separate listener for resetting the scroll position on page changes, and also on deactivate Mojo.listen($('launcher_root'), Mojo.Event.propertyChange, this.resetScrollPosition.bindAsEventListener(this)); Mojo.listen(this.controller.document, Mojo.Event.deactivate, this.resetScrollPosition.bindAsEventListener(this)); },

ready: function() { this.globalSearchAssistant.ready(); },

</source>
  • Add the following method somewhere else in the file, I suggest just below the ready method and before the deleteAllPages method, around line 105 (don't forget the comma after the closing brace, unless you add it right at the end of the class, as the last method):
<source lang="javascript">

resetScrollPosition: function(event) { var pageIndex = (event.type === 'mojo-event-deactivate') ? this.activePageIndex : event.value; var scroller = this.getPageScroller(pageIndex); if (scroller && scroller.mojo) { scroller.mojo.revealTop(); } },

</source>
  • Save the file and quit vi.
  • Remount the filesystem as read only - this should reboot your Pre:
<source lang="bash">

sudo rootfs_open -w

</source>


Patch Process

An older version of the patch is in the git/Preware repository, hopefully this version will be submitted soon. Until then, you can copy and paste the source below. Visit Applying Patches for info on how to use it. You can also apply it using webOS Quick Install. To apply the patch, follow the instructions above, and after remounting the filesystem as read/write, do the following:

  • Apply the patch (In this example, I have the patch file located in my home directory under patches):
<source lang="bash">

cd / sudo patch -p0 --backup-if-mismatch < ~/patches/reset-scroll.patch

</source>

This is what you should see if it ran properly: <source lang="text"> patching file /usr/lib/luna/system/luna-applauncher/app/controllers/launcher-assistant.js

</source>
  • Remount the filesystem as read only as described above.


Patch Source (reset-scroll.patch)

<source lang="diff"> --- /usr/lib/luna/system/luna-applauncher/app/controllers/launcher-assistant.js.orig Sat Dec 5 11:48:12 2009 +++ /usr/lib/luna/system/luna-applauncher/app/controllers/launcher-assistant.js Thu Dec 3 19:42:03 2009 @@ -98,5 +98,9 @@

		// setup the initial dimensions for launcher/global-search
		this.adjustLayout();

+ + // add a separate listener for resetting the scroll position on page changes, and also on deactivate + Mojo.listen($('launcher_root'), Mojo.Event.propertyChange, this.resetScrollPosition.bindAsEventListener(this)); + Mojo.listen(this.controller.document, Mojo.Event.deactivate, this.resetScrollPosition.bindAsEventListener(this));

	},
	
	ready: function() {	

@@ -188,6 +188,12 @@

	onResize: function(event) {
		this.adjustLayout();
	},

+ resetScrollPosition: function(event) { + var pageIndex = (event.type === 'mojo-event-deactivate') ? this.activePageIndex : event.value; + var scroller = this.getPageScroller(pageIndex); + if (scroller && scroller.mojo) { scroller.mojo.revealTop(); } + }, +

	/* remove page data and their corresponding HTML */
	deleteAllPages: function() {


</source>