Page 1 of 1

"Window" plugin

Posted: Wed Apr 13, 2016 1:33 am
by Terran
As I'm a lazy person so I don't want to change my FreePIE script whenever I switch the game I'm playing :D .

So I wanted FreePIE to know which game I'm playing and "activate" different parts of the script which as specifically made for a game. To figure that out FreePIE needs to know which process is owning the foreground window. As there was no such functionallity in FreePIE I've created my own plugin for that. It has three functions and methods to be used in a script:
  • Window.is_active(<process name>) - test if a process is owning the foreground window
  • Window.active - get the name of the process owning the foreground window
  • Window.activate - make a process the foreground window
I've implemented it as a core plugin as I assume that many ppl might want such a functionality for FreePIE.

My pull request: https://github.com/AndersMalmgren/FreePIE/pull/79

Re: "Window" plugin

Posted: Wed Apr 13, 2016 6:04 am
by CyberVillain
Hi, i will look at this and get back to you, was a few things that was strange and that do not folllow the FreePIE code conventions (That we should document).

One question, right away

Code: Select all

                } else {
                    ActiveWindow = "unable to find foreground window";
                }
            } catch (Exception ex)
            {
                ActiveWindow = "error while finding foreground window: " + ex.ToString();
Setting the propety ActiveWindow to something else than null or a title of the active window seems wrong, and outside of the scope of a propety named ActiveWindow, mayne throw error or set ActiveWidnow no null?

Re: "Window" plugin

Posted: Wed Apr 13, 2016 7:03 am
by CyberVillain
I merged your code and did some changes

https://github.com/AndersMalmgren/FreeP ... ndowPlugin

Also I changed from ProcessName to MainWindowTitle since the name of the plugin Window suggests thats its the name of the window you want not the process. Maybe have both options?

Re: "Window" plugin

Posted: Wed Apr 13, 2016 2:46 pm
by Terran
CyberVillain wrote: One question, right away

Code: Select all

                } else {
                    ActiveWindow = "unable to find foreground window";
                }
            } catch (Exception ex)
            {
                ActiveWindow = "error while finding foreground window: " + ex.ToString();
Setting the propety ActiveWindow to something else than null or a title of the active window seems wrong, and outside of the scope of a propety named ActiveWindow, mayne throw error or set ActiveWidnow no null?
I shouldn't really matter as that property is used for comparing or reporting only. What actually happens in such a situation should be handled by the python script and not throw an error.

Re: "Window" plugin

Posted: Wed Apr 13, 2016 2:53 pm
by Terran
CyberVillain wrote:I merged your code and did some changes

https://github.com/AndersMalmgren/FreeP ... ndowPlugin

Also I changed from ProcessName to MainWindowTitle since the name of the plugin Window suggests thats its the name of the window you want not the process. Maybe have both options?
That's totally fine with me, it's about the idea for such a plugin, not about how it is implemented. I only occasionally code in c# or python nor do I have your vision of how a plugin for FreePIE should look like ;)

I's a bit more to do to figure the process for a window title so I left out that part as using process names will do the job.

Re: "Window" plugin

Posted: Wed Apr 13, 2016 3:58 pm
by Terran
I took a deeper look at your changes and now I get a better understanding of how a plugin should be implemented.

But I would change back the "MainWindowTitle" to "ProcessName" as that's what you actually get. The DLL function "GetWindowText" is not used at all (a leftover from my earlier test which i forgot to remove).

E.g. if "VLC media player" is the foreground window you will get "vlc" as the process name and you use "vlc" to make that process the foreground window.

Re: "Window" plugin

Posted: Thu Apr 14, 2016 12:42 am
by CyberVillain
Yes, i will do that.

Re: "Window" plugin

Posted: Thu Apr 14, 2016 3:06 am
by CyberVillain
its way too expensive to ask for active window on each itteration of the script. Need to add a StopWatch and do it 500ms or so
cpu.png

Re: "Window" plugin

Posted: Thu Apr 14, 2016 3:19 am
by CyberVillain
Added a 100ms thottle. Meaning it will update with 100ms maximum rate

Re: "Window" plugin

Posted: Thu Apr 14, 2016 6:34 am
by Terran
Cool, that's something I totally missed!

I see you made the plugin an "updateable" plugin. What's about that? What's the difference/advantage?

Re: "Window" plugin

Posted: Thu Apr 14, 2016 7:07 am
by CyberVillain
You can get updates only when active window changes, like

Code: Select all

def update():
	diagnostics.debug(window.active)
	
if starting:
	window.update += update

Re: "Window" plugin

Posted: Thu Apr 14, 2016 7:49 am
by Terran
OK, understood. So I could do "something" whenever the active window changes without having to test for it on each iteration of the script. I already can think of how to use it for my purposes :D

Re: "Window" plugin

Posted: Thu Apr 14, 2016 10:40 am
by CyberVillain
Exactly, yeah, i figured that could be useful :D