"Window" plugin

Official forum for open source FreePIE discussion and development.
Post Reply
Terran
One Eyed Hopeful
Posts: 10
Joined: Tue Mar 22, 2016 4:51 pm

"Window" plugin

Post 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
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: "Window" plugin

Post 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?
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: "Window" plugin

Post 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?
Terran
One Eyed Hopeful
Posts: 10
Joined: Tue Mar 22, 2016 4:51 pm

Re: "Window" plugin

Post 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.
Terran
One Eyed Hopeful
Posts: 10
Joined: Tue Mar 22, 2016 4:51 pm

Re: "Window" plugin

Post 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.
Terran
One Eyed Hopeful
Posts: 10
Joined: Tue Mar 22, 2016 4:51 pm

Re: "Window" plugin

Post 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.
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: "Window" plugin

Post by CyberVillain »

Yes, i will do that.
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: "Window" plugin

Post 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
You do not have the required permissions to view the files attached to this post.
Last edited by CyberVillain on Thu Apr 14, 2016 3:19 am, edited 1 time in total.
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: "Window" plugin

Post by CyberVillain »

Added a 100ms thottle. Meaning it will update with 100ms maximum rate
Terran
One Eyed Hopeful
Posts: 10
Joined: Tue Mar 22, 2016 4:51 pm

Re: "Window" plugin

Post 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?
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: "Window" plugin

Post 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
Terran
One Eyed Hopeful
Posts: 10
Joined: Tue Mar 22, 2016 4:51 pm

Re: "Window" plugin

Post 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
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: "Window" plugin

Post by CyberVillain »

Exactly, yeah, i figured that could be useful :D
Post Reply

Return to “FreePIE”