Exemplo n.º 1
0
static bool opt_workspace(Tokenizer *tokz, int n, Token *toks)
{
	char *name=TOK_STRING_VAL(&(toks[1]));
	
	if(*name=='\0'){
		tokz_warn(tokz, toks[1].line, "Empty name");
		return FALSE;
	}
	
	current_ws=create_workspace(current_screen, name, FALSE);
	
	if(current_ws==NULL)
		return FALSE;
	
	return TRUE;
}
Exemplo n.º 2
0
/**
@brief    Adds a frame to a workspace, creating the workspace if required.
          Indirectly creates workspaces and frames.  Gets the program name from the frame using the class hints (load_program_name).
          If the program name doesn't match the name of any workspace, creates a new workspace.
          If the workspace is new, switch to the workspace.  Try and tile the frame if its mode is tiling.
          Decide whether to show the frame and whether to focus it.
@return   the index of the workspace the frame was inserted into or -1 if an error occurred.
**/
int
add_frame_to_workspace(Display *display, struct Workspace_list *workspaces, Window framed_window, int *current_workspace, struct Workspace **frames
, struct Popup_menu *window_menu
, struct Separators *seps
, const struct Workarea *workarea
, struct Themes *themes, struct Cursors *cursors, struct Atoms *atoms) {

  int home_w;  //index of the home workspace of the frame
  int true_frame_index; //index of the frame in the global frame list in workspaces

  Bool new_workspace = False;  //boolean indicator to check if a workspace was just created.
  char *program_name = load_program_name(display, framed_window);

  if(program_name == NULL) {
    #ifdef SHOW_MAP_REQUEST_EVENT
    printf("Warning, could not load program name for window %lu. ", framed_window);
    printf("Creating default workspace\n");
    #endif
    make_default_program_name(display, framed_window, "Other Programs");
    program_name = load_program_name(display, framed_window);
  }
  if(program_name == NULL) {perror("Error: out of memory"); return -1;} //probably out of memory

  for(home_w = 0; home_w < workspaces->used_workspaces; home_w++) {
    if(strcmp(program_name, workspaces->list[home_w].workspace_name) == 0) {
      XFree(program_name);
      break;
    }
  }
  if(home_w == workspaces->used_workspaces) { //create_statup workspaces only creates a workspace if there is at least one
    home_w = create_workspace(display, workspaces, program_name, themes);
    if(home_w < 0) { perror("Error: could not create new workspace\n"); return -1; }
    new_workspace = True;
  }

  if(ensure_empty_frame_slots(workspaces) == False) return -1;
  if(ensure_empty_frame_reference_slots(&workspaces->list[home_w]) == False) return -1;

  true_frame_index = workspaces->used_frames;
  if(!create_frame(display, &workspaces->frame_list[true_frame_index], framed_window, window_menu, seps, workarea, themes, cursors, atoms)) {
    //if the window wasn't created, and the workspace is now empty, remove the workspace
    if(new_workspace) { remove_workspace(display, workspaces, home_w);  }
    return -1;
  }

  workspaces->used_frames++;
  #ifdef SHOW_MAP_REQUEST_EVENT
  printf("Workspace %d, real frame index %d, frame_name %s, window %lu, workspace_name %s\n", home_w, true_frame_index
  , workspaces->frame_list[true_frame_index].window_name, framed_window, workspaces->list[home_w].workspace_name);
  #endif

  check_and_set_new_frame_focus (display, &workspaces->frame_list[true_frame_index], &workspaces->list[home_w]);

  //check if it's neutral
  Bool show_in_other_workspaces = suitable_for_foreign_workspaces(&workspaces->frame_list[true_frame_index]);
  enum Window_state original_state = workspaces->frame_list[true_frame_index].state; //in case it is fullscreen

  { //save state of window in home workspace and other workspaces if it's meant to be shown in other workspaces.
    //Otherwise the saved state entry will simply zero'd.
    int workspace_index = 0;

    do {
      if(!show_in_other_workspaces) workspace_index = home_w; //only do one pass if we don't want to make it available

      workspaces->list[workspace_index].states[true_frame_index].need_to_tile = 0; //reset

      if(workspace_index == home_w) {
        workspaces->list[workspace_index].states[true_frame_index].available = 1;
        if(workspaces->frame_list[true_frame_index].mode == tiling  &&  home_w != *current_workspace) {
          workspaces->list[workspace_index].states[true_frame_index].need_to_tile = 1;
        }
        change_frame_state(display, &workspaces->frame_list[true_frame_index], original_state, seps, workarea, themes, atoms);
        save_frame_state(&workspaces->list[workspace_index].states[true_frame_index], &workspaces->frame_list[true_frame_index]);
      }
      else if (show_in_other_workspaces) {
        workspaces->list[workspace_index].states[true_frame_index].available = 2;
        change_frame_state(display, &workspaces->frame_list[true_frame_index], minimized, seps, workarea, themes, atoms);
        save_frame_state(&workspaces->list[workspace_index].states[true_frame_index], &workspaces->frame_list[true_frame_index]);
      }

      workspace_index++;
    }
    while(show_in_other_workspaces  &&  workspace_index < workspaces->used_workspaces);
  }

  if(home_w == *current_workspace  &&  *current_workspace != -1) { //new window is in the current workspace
     //save the reference
    struct Workspace *workspace = &workspaces->list[*current_workspace];
    int frame_ref_index = workspace->used;
    workspace->list[frame_ref_index] = &workspaces->frame_list[true_frame_index];
    workspace->used++;

    change_frame_state(display, &workspaces->frame_list[true_frame_index], original_state, seps, workarea, themes, atoms);
    if(workspace->list[frame_ref_index]->mode == tiling  &&  workspace->list[frame_ref_index]->state != fullscreen) {
      if(!redrop_frame(display, workspace, frame_ref_index, workarea, themes)) {
        change_frame_state(display, workspace->list[frame_ref_index], minimized, seps, workarea, themes, atoms);
      }
    }
    #ifdef SHOW_MAP_REQUEST_EVENT
    printf("Created and mapped window in workspace %d\n", *current_workspace);
    #endif
    if(workspaces->frame_list[true_frame_index].state != minimized) XMapWindow(display, workspace->list[frame_ref_index]->widgets[frame_parent].widget);
    XMapWindow(display, workspace->list[frame_ref_index]->menu.item);
    if(workspace->list[frame_ref_index]->focussed) {
      recover_focus(display, &workspaces->list[*current_workspace], atoms);
    }

    update_client_list(display, &workspaces->list[*current_workspace], atoms);
  }

  if(home_w != *current_workspace) {
    change_to_workspace(display, workspaces, current_workspace, frames, home_w, seps, workarea, themes, atoms);
  }

  XFlush(display);
  return home_w;
}