Set wanderer screen title

Guest · 2659

Gundam

  • Guest
on: November 16, 2018, 08:17:53 AM
how do I change the screen title of Workbench/Wanderer screen in a c++ program ?

Can some dev do an example code, please ?



paolone

  • Legendary Member
  • *****
    • Posts: 568
    • Karma: +90/-0
Reply #1 on: November 16, 2018, 03:45:26 PM
Isn't there an option in wanderer prefs to do that? in this case, just donwload AROS sources and look there.


magorium

  • Legendary Member
  • *****
    • Posts: 632
    • Karma: +62/-0
  • Convicted non contributor
Reply #2 on: November 17, 2018, 03:45:37 PM
@paolone:
TS seems to want to it programmatically. Yes, TS can indeed search inside the sources for that but that would hide a underlying problem.

@Gundam:
Why would you want to do that ? I'm not questioning your motives there rather that it is uncustom to want to change that. The first 'workbench' screen is a special public screen and as such is somewhat of a special case.

The usual way of 'changing the wb screen title' is by opening your own window on the workbench in which case you can use SetWindowTitles() to 'change' the title of the screen. You could also achieve something similar by applying that to the workbench (backdrop) window..... that is, unless you do not have such window ? Therefor i had to ask why.

edit:
funnily enough i just had a little peek and there are two FIXME's inside SetWindowTitles() sources of AROS.... is that perhaps what you're hinting at @Gundam ? and fwiw and imho yes these should be strdupped.... (although i haven't checked with OS 3.x... it just makes logical sense)
« Last Edit: November 17, 2018, 04:25:50 PM by magorium »



BSzili

  • Newbie
  • *
    • Posts: 44
    • Karma: +80/-0
    • My AROS, MorphOS and AmigaOS4 ports
Reply #3 on: November 18, 2018, 06:33:06 AM
This is tricky, because once you've changed a screen's title, you became responsible for that string. For example if you want to make it permanent after your program exits, you have to AllocMem/AllocVec some public memory for it, but then you end up leaking memory after each change.
If the goal is to change the title only for the duration of the program, then this may work:
Code: [Select]
struct Screen *screen = LockPubScreen(NULL);
if (screen)
{
 STRPTR oldTitle = screen->Title;
 SetWindowTitles(screen->FirstWindow, (STRPTR)~0, "New Screen Title");
 // do your thing
 SetWindowTitles(screen->FirstWindow, (STRPTR)~0, oldTitle);
 UnlockPubScreen(NULL, screen);
}
Keep in mind, that this is a bit hackish, so proceed with caution.

This is just like television, only you can see much further.


Gundam

  • Guest
Reply #4 on: November 18, 2018, 09:04:01 AM
This is tricky, because once you've changed a screen's title, you became responsible for that string. For example if you want to make it permanent after your program exits, you have to AllocMem/AllocVec some public memory for it, but then you end up leaking memory after each change.
If the goal is to change the title only for the duration of the program, then this may work:
Code: [Select]
struct Screen *screen = LockPubScreen(NULL);
if (screen)
{
 STRPTR oldTitle = screen->Title;
 SetWindowTitles(screen->FirstWindow, (STRPTR)~0, "New Screen Title");
 // do your thing
 SetWindowTitles(screen->FirstWindow, (STRPTR)~0, oldTitle);
 UnlockPubScreen(NULL, screen);
}
Keep in mind, that this is a bit hackish, so proceed with caution.


Thanks !!



o1i

  • Newbie
  • *
    • Posts: 41
    • Karma: +6/-0
Reply #5 on: November 19, 2018, 02:24:34 AM
Setting the screen title for a foreign window is not a good idea. The screen title (nearly) always belongs to a window. So I would open a new window on the workbench screen (this window can be made small and invisible easily). As long as this window stays active, your screen title will be shown.



Gundam

  • Guest
Reply #6 on: November 19, 2018, 08:31:39 AM
Setting the screen title for a foreign window is not a good idea. The screen title (nearly) always belongs to a window. So I would open a new window on the workbench screen (this window can be made small and invisible easily). As long as this window stays active, your screen title will be shown.


Thanks for replying!

now, can you write a short example code (in c++) on how to open an arexx port , wait for messages to arrive and then process them ?

the aros wiki is not very clear on this.



Gundam

  • Guest
Reply #7 on: November 19, 2018, 12:13:23 PM
here's a little program that opens an arexx port and waits for messages from an arexx script:

#include <proto/exec.h>
#include <proto/alib.h>
#include <proto/rexxsyslib.h>
#include <stdio.h>
 

struct MsgPort *CreatePubPort (char *name)
/* create a port if port name is not already used */
{
  struct MsgPort *port;

  port = NULL;
  Forbid ();
  if (FindPort (name) == NULL) { 
    printf("port was created\n");
    port = CreatePort (name, 0);
  } 
   
  Permit ();
  return (port);
}

void ProcessRexxMsg (struct RexxMsg *msg)
{
  //printf("process msg\n");
 
  char    *value;

  printf("-- Now processing msg ...\n\n");
   
  if (!GetRexxVar(msg,"TheVar",&value))  //*** HERE THE PROGRAM CRASHES
  {
            /* The value was gotten and now is pointed to by value */
            printf("Value of TheVar is %sn",value);
  }
}


/* Now that the port is created we just need to wait for a message.  */

void PubPortWait (struct MsgPort *port)
/* wait for a message or signal on our pubport */
{
    ULONG port_mask, signals;
    struct RexxMsg *msg;

    port_mask = (1L << port->mp_SigBit);
    while (1)
    {
        signals = Wait (port_mask | SIGBREAKF_CTRL_C);
        if (signals & SIGBREAKF_CTRL_C)
       
        break;
        if (signals & port_mask)
        {
                while ((msg = (struct RexxMsg *) GetMsg (port)) != NULL)
                {
                        ProcessRexxMsg (msg); /* routine parses the REXX message */
                        ReplyMsg ((struct Message *) msg);
                        printf("-- msg was processed\n\n");
                }
        }
    }
}



int main() {

   struct MsgPort *port;
   struct Library *RexxSysBase;

   RexxSysBase = OpenLibrary("rexxsyslib.library", 0);
   
   if (RexxSysBase) {
      port = CreatePubPort ("MYPORT");
      PubPortWait (port);
   }

   DeletePort(port);
   CloseLibrary(RexxSysBase);     
   return 0;
}


here's the script:

/* **** */

OPTIONS RESULTS
ADDRESS MYPORT 'TheVar=10'



I first run the C program.
When I execute the arexx script, the program crashes saying "Regina helper... Illegal instruction".

The crash occurs in the "ProcessRexxMsg" subroutine.

What could the cause be ?